Polish the complexpingpong example

- Use QDBusServiceWatcher to detect that pong service became available
  (QDBusConnectionInterface::serviceOwnerChanged() signal is deprecated).
- Use new connection syntax.

Task-number: QTBUG-28082
Change-Id: I7b93b961ee6d45aaeefab77fa1d1943e38b4a4c0
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Alexander Volkov 2015-10-16 01:36:16 +03:00
parent 3cae29b746
commit 59b860450f
3 changed files with 10 additions and 10 deletions

View File

@ -49,11 +49,9 @@
#include "ping-common.h"
#include "complexping.h"
void Ping::start(const QString &name, const QString &oldValue, const QString &newValue)
void Ping::start(const QString &name)
{
Q_UNUSED(oldValue);
if (name != SERVICE_NAME || newValue.isEmpty())
if (name != SERVICE_NAME)
return;
// open stdin for reading
@ -105,10 +103,12 @@ int main(int argc, char **argv)
return 1;
}
QDBusServiceWatcher serviceWatcher(SERVICE_NAME, QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForRegistration);
Ping ping;
ping.connect(QDBusConnection::sessionBus().interface(),
SIGNAL(serviceOwnerChanged(QString,QString,QString)),
SLOT(start(QString,QString,QString)));
QObject::connect(&serviceWatcher, &QDBusServiceWatcher::serviceRegistered,
&ping, &Ping::start);
QProcess pong;
pong.start("./complexpong");

View File

@ -49,7 +49,7 @@ class Ping: public QObject
{
Q_OBJECT
public slots:
void start(const QString &, const QString &, const QString &);
void start(const QString &);
public:
QFile qstdin;
QDBusInterface *iface;

View File

@ -61,7 +61,7 @@ void Pong::setValue(const QString &newValue)
void Pong::quit()
{
QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
QTimer::singleShot(0, QCoreApplication::instance(), &QCoreApplication::quit);
}
QDBusVariant Pong::query(const QString &query)
@ -88,7 +88,7 @@ int main(int argc, char **argv)
QObject obj;
Pong *pong = new Pong(&obj);
pong->connect(&app, SIGNAL(aboutToQuit()), SIGNAL(aboutToQuit()));
QObject::connect(&app, &QCoreApplication::aboutToQuit, pong, &Pong::aboutToQuit);
pong->setProperty("value", "initial value");
QDBusConnection::sessionBus().registerObject("/", &obj);