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:
parent
3cae29b746
commit
59b860450f
@ -49,11 +49,9 @@
|
|||||||
#include "ping-common.h"
|
#include "ping-common.h"
|
||||||
#include "complexping.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)
|
||||||
|
|
||||||
if (name != SERVICE_NAME || newValue.isEmpty())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// open stdin for reading
|
// open stdin for reading
|
||||||
@ -105,10 +103,12 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDBusServiceWatcher serviceWatcher(SERVICE_NAME, QDBusConnection::sessionBus(),
|
||||||
|
QDBusServiceWatcher::WatchForRegistration);
|
||||||
|
|
||||||
Ping ping;
|
Ping ping;
|
||||||
ping.connect(QDBusConnection::sessionBus().interface(),
|
QObject::connect(&serviceWatcher, &QDBusServiceWatcher::serviceRegistered,
|
||||||
SIGNAL(serviceOwnerChanged(QString,QString,QString)),
|
&ping, &Ping::start);
|
||||||
SLOT(start(QString,QString,QString)));
|
|
||||||
|
|
||||||
QProcess pong;
|
QProcess pong;
|
||||||
pong.start("./complexpong");
|
pong.start("./complexpong");
|
||||||
|
@ -49,7 +49,7 @@ class Ping: public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public slots:
|
public slots:
|
||||||
void start(const QString &, const QString &, const QString &);
|
void start(const QString &);
|
||||||
public:
|
public:
|
||||||
QFile qstdin;
|
QFile qstdin;
|
||||||
QDBusInterface *iface;
|
QDBusInterface *iface;
|
||||||
|
@ -61,7 +61,7 @@ void Pong::setValue(const QString &newValue)
|
|||||||
|
|
||||||
void Pong::quit()
|
void Pong::quit()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
|
QTimer::singleShot(0, QCoreApplication::instance(), &QCoreApplication::quit);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusVariant Pong::query(const QString &query)
|
QDBusVariant Pong::query(const QString &query)
|
||||||
@ -88,7 +88,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
QObject obj;
|
QObject obj;
|
||||||
Pong *pong = new Pong(&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");
|
pong->setProperty("value", "initial value");
|
||||||
QDBusConnection::sessionBus().registerObject("/", &obj);
|
QDBusConnection::sessionBus().registerObject("/", &obj);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user