{"id":185950,"date":"2013-07-16T15:40:04","date_gmt":"2013-07-16T11:40:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=185950"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=185950","title":{"rendered":"<span class=\"post_title\">QtDbus \u0427\u0430\u0441\u0442\u044c 2. \u041f\u043e\u0431\u0435\u0434\u043d\u043e\u0435 \u0441\u0438\u044f\u043d\u0438\u0435 \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0443\u043c\u0430<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/habrahabr.ru\/post\/185212\/\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f<\/a> \u0447\u0430\u0441\u0442\u044c \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0430 \u043c\u0440\u0430\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b, \u043d\u043e \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e, \u0433\u043e\u0440\u0430\u0437\u0434\u043e, \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435.<\/p>\n<h5>\u0420\u0430\u0437\u0431\u043e\u0440 \u0431\u043e\u043d\u0443\u0441-\u043b\u0435\u0432\u0435\u043b\u0430<\/h5>\n<p>\u0418\u0442\u0430\u043a, \u0441\u043f\u0441\u0430\u0438\u0431\u043e \u0445\u0430\u0431\u0440\u0430\u0436\u0438\u0442\u0435\u043b\u044e \u043e\u043d \u043e\u0431\u0440\u0430\u0442\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 QDbusAbstractAdaptor \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c. \u0414\u043b\u044f \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u043e\u0432\u043e\u0441\u0442\u044c\u044e, \u0442.\u043a. \u044f \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u044b\u043a, \u0447\u0442\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0431\u044b\u0442\u044c. \u041c\u043e\u0436\u0435\u0442 \u044d\u0442\u043e \u0443\u0431\u0435\u0440\u0435\u0436\u0435\u0442 \u0435\u0449\u0435 \u043a\u043e\u0433\u043e-\u0442\u043e \u043e\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043b\u044f\u043f\u0430.<\/p>\n<p>  \u0412\u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043c\u043e\u0435 \u043d\u0435\u0437\u043d\u0430\u043d\u0438\u0435 \u043f\u0430\u0442\u0435\u0440\u043d\u043e\u0432, \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0442\u0435\u043d \u00ab\u0410\u0434\u0430\u043f\u0442\u0435\u0440\u00bb. \u0422\u0430\u043a \u0432\u043e\u0442 QAbstractAdaptor \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043e\u043d \u0438 \u0435\u0441\u0442\u044c. \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0438, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043b\u0438\u0431\u044b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c:<a name=\"habracut\"><\/a><br \/>  \u041f\u0440\u043e\u0435\u043a\u0442 Pong:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;QCoreApplication&gt; #include &lt;QDBusConnection&gt; #include &lt;QDBusError&gt; #include &lt;QDebug&gt;  #include &quot;Pong.h&quot; #include &quot;..\/serviceNameAndProperty.h&quot; int main(int argc, char *argv[]) {     QCoreApplication a(argc, argv);     QDBusConnection connection = QDBusConnection::sessionBus();     Pong pong;     if( ! connection.registerObject(&quot;\/&quot;, &pong)){         fprintf(stderr, &quot;%s\\n&quot;,                 qPrintable(&quot;Can't register object&quot;));         exit(1);     }     qDebug()&lt;&lt;&quot;Pong connected to D-bus&quot;;      if (!connection.registerService(SERVICE_NAME)) {         fprintf(stderr, &quot;%s\\n&quot;,                 qPrintable(QDBusConnection::sessionBus().lastError().message()));         exit(1);     }     qDebug()&lt;&lt;&quot;Test service start&quot;;     return a.exec(); } <\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Pong.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#ifndef PONG_H #define PONG_H #include &lt;QDBusAbstractAdaptor&gt; #include &lt;QDBusVariant&gt; #include &lt;QDBusArgument&gt; #include &lt;QDBusContext&gt;  #include &quot;..\/serviceNameAndProperty.h&quot;  class Pong;  class PongAdapter : public QDBusAbstractAdaptor {     Q_OBJECT     Q_CLASSINFO(&quot;D-Bus Interface&quot;, BUFFER_NAME)     Q_PROPERTY(QString IMAGE_DATA_SHARED_ID READ imageDataSharedId) public:     explicit PongAdapter(Pong *parent);      QString imageDataSharedId();  public slots:     TestStructure structureField(); signals:     void callingMe(QString, QString); private:     Pong * m_parentPong;  };  class Pong : public QObject, public QDBusContext {     Q_OBJECT public:     Pong()     {         m_pongAdapter = new PongAdapter(this);         QObject::connect(this, SIGNAL(callingMe(QString,QString)), m_pongAdapter, SIGNAL(callingMe(QString, QString)));         m_imageDataSharedId = &quot;testImageBufferId&quot;;      } public:     QString imageDataSharedId();     TestStructure& structureField();  signals:     void callingMe(QString, QString); private:     PongAdapter *m_pongAdapter;     QString m_imageDataSharedId;     TestStructure test;  }; #endif \/\/ PONG_H&gt;<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Pong.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &quot;Pong.h&quot; #include &lt;QDebug&gt; #include &lt;QDBusMetaType&gt; #include &lt;QDBusConnection&gt; #include &lt;QDBusMessage&gt;  PongAdapter::PongAdapter(Pong *parent) :     QDBusAbstractAdaptor(parent) {     m_parentPong = parent;     qRegisterMetaType&lt;TestStructure&gt;(&quot;TestStructure&quot;);     qDBusRegisterMetaType&lt;TestStructure&gt;();  }  QString PongAdapter::imageDataSharedId() {     return m_parentPong-&gt;imageDataSharedId(); }  TestStructure PongAdapter::structureField() {     return m_parentPong-&gt;structureField(); }  QString Pong::imageDataSharedId() {     return m_imageDataSharedId; }  TestStructure &Pong::structureField() {     qDebug()&lt;&lt;&quot;Me calld&quot;&lt;&lt;QDBusConnection::sessionBus().baseService()&lt;&lt;message().service();     emit callingMe(QString(&quot;Panic&quot;), QString(&quot;Super panic&quot;));     test.str = QString(&quot;ku&quot;);     test.id =2;     return test; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 Ping:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt;  #include &lt;QObject&gt; #include &lt;QCoreApplication&gt; #include &lt;QDBusConnection&gt; #include &lt;QDBusConnectionInterface&gt; #include &lt;QDBusServiceWatcher&gt; #include &lt;QDebug&gt;  #include &quot;Ping.h&quot; #include &quot;..\/serviceNameAndProperty.h&quot; int main(int argc, char *argv[]) {     QCoreApplication a(argc, argv);     Ping ping;      if (!QDBusConnection::sessionBus().isConnected()) {              fprintf(stderr, &quot;Cannot connect to the D-Bus session bus.\\n&quot;                      &quot;To start it, run:\\n&quot;                      &quot;\\teval `dbus-launch --auto-syntax`\\n&quot;);              return 1;     }     qDebug()&lt;&lt;&quot;Ping connected to D-bus&quot;;       QDBusConnectionInterface *iface = QDBusConnection::sessionBus().interface();     QDBusServiceWatcher watcher;     watcher.setConnection(QDBusConnection::sessionBus());;     watcher.addWatchedService(ping.m_aviableServiceName); \/\/    QObject::connect(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),&ping,  SLOT(manageConnection(QString,QString,QString)));     QObject::connect(&watcher, SIGNAL(serviceRegistered(QString)), &ping, SLOT(connectToService(QString)));      QStringList registedServices = iface-&gt;registeredServiceNames();     if(registedServices.contains(ping.m_aviableServiceName))         ping.connectToService(ping.m_aviableServiceName);     return a.exec(); <\/code><\/pre>\n<p>  }<\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Ping.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#ifndef PING_H #define PING_H  #include &lt;QObject&gt; #include &lt;QDBusAbstractInterface&gt; #include &lt;qdbusinterface.h&gt;  class Ping : public QObject {     Q_OBJECT public:     explicit Ping(QObject *parent = 0); public slots:     void manageConnection(const QString &name, const QString &oldVAlue, const QString &newValue);     void connectToService(const QString &name);     void disconnect(const QString &name);     void reacoOnMeCalling(QString message, QString message2); public:     QString m_aviableServiceName; private:     QDBusInterface *m_interface;     QString m_interfaceName;     static const QString _propertyName; };  #endif \/\/ PING_H <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Ping.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &quot;Ping.h&quot; #include &quot;..\/serviceNameAndProperty.h&quot; #include &lt;QDBusConnectionInterface&gt; #include &lt;QDebug&gt; #include &lt;QDBusMetaType&gt;  const QString Ping::_propertyName(QUIOTING(IMAGE_DATA_SHARED_ID)); Ping::Ping(QObject *parent) :     QObject(parent) {     m_interface = NULL;     m_interfaceName = QString(BUFFER_NAME);     m_aviableServiceName = QString(SERVICE_NAME);     qRegisterMetaType&lt;TestStructure&gt;(&quot;TestStructure&quot;);     qDBusRegisterMetaType&lt;TestStructure&gt;(); }  void Ping::manageConnection(const QString& name, const QString &oldVAlue, const QString &newValue) {     Q_UNUSED(oldVAlue)     if(name != m_aviableServiceName)         return;     if(newValue.isEmpty())         disconnect(name);     else         connectToService(name);  }  void Ping::connectToService(const QString &name) {     if(name != m_aviableServiceName)         return;     qDebug()&lt;&lt;&quot;Connceting&quot;;     m_interface = new QDBusInterface(name, &quot;\/&quot;, m_interfaceName, QDBusConnection::sessionBus(), this);     QObject::connect(m_interface, SIGNAL(callingMe(QString, QString)), this, SLOT(reacoOnMeCalling(QString, QString)));     if(!m_interface-&gt;isValid()){         qDebug()&lt;&lt;&quot;Invalid interface&quot;&lt;&lt;m_interface-&gt;lastError();         delete m_interface;         m_interface = NULL;         return;     }     qDebug()&lt;&lt;m_interface-&gt;interface();      QVariant var(&quot;sss&quot;);     var = m_interface-&gt;property(&quot;imageDataSharedId&quot;);     qDebug()&lt;&lt;var;     QDBusReply&lt;TestStructure&gt; reply= m_interface-&gt;call(&quot;structureField&quot;);     if(reply.isValid())     {         TestStructure testStructure = reply.value();         qDebug()&lt;&lt;testStructure.id&lt;&lt;testStructure.str;     } }  void Ping::disconnect(const QString &name) {     if(name != m_aviableServiceName)         return;     if(name != m_interface-&gt;service())         return;      delete m_interface;     m_interface = NULL;     qDebug()&lt;&lt;&quot;Disconnect&quot;; }  void Ping::reacoOnMeCalling(QString message, QString message2) {     qDebug()&lt;&lt;message&lt;&lt;message2; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0431\u0449\u0438\u0439 \u0444\u0430\u0439\u043b serviceNameAndProperty.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once #include&lt;QMetaType&gt; #include &lt;QString&gt; #include &lt;QDBusArgument&gt; #define SERVICE_NAME &quot;ru.sonarh.dbus.pong&quot; #define BUFFER_NAME &quot;ru.buffer&quot; #define IMAGE_DATA_SHARED_ID imageDataSharedId #define QUIOTING(text) #text   struct TestStructure{     int id;     QString str; }; Q_DECLARE_METATYPE(TestStructure)  static QDBusArgument& operator &lt;&lt;(QDBusArgument &argument, const TestStructure & arg) {     argument.beginStructure();     argument&lt;&lt;arg.id&lt;&lt;arg.str;     argument.endStructure();     return argument; }  static const QDBusArgument& operator &gt;&gt;(const QDBusArgument &argument, TestStructure & arg) {     argument.beginStructure();     argument&gt;&gt;arg.id&gt;&gt;arg.str;     argument.endStructure();     return argument; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<h5>\u0418 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438, \u043a\u0430\u043a \u044d\u0442\u043e \u044e\u0437\u0430\u0442\u044c?<\/h5>\n<p> \u0420\u0430\u0434\u0438 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044e \u0441\u0435\u0431\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e. \u0411\u043b\u0430\u0433\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435 \u2014 \u043c\u0430\u0442\u044c \u0443\u0447\u0435\u043d\u0438\u044f.<br \/>  \u0418\u0442\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 Pong, \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0435\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e D-Bus. \u0427\u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e:  <\/p>\n<ol>\n<li>\u041f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0441\u044f \u043a D-Bus \u0434\u0435\u043c\u043e\u043d\u0443. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0433\u0434\u0435 \u0443\u0433\u043e\u0434\u043d\u043e, \u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0448\u0438\u043d \u0435\u0441\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0438\u0434\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439\n<pre><code class=\"cpp\">if (!QDBusConnection::sessionBus().isConnected()) {<\/code><\/pre>\n<\/li>\n<li>\u0420\u0430\u0434\u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u0437\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0438\u043c\u044f, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 DNS. \u041c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 Pong:\n<pre><code class=\"cpp\">if (!connection.registerService(SERVICE_NAME)) {<\/code><\/pre>\n<p><b>\u0412\u0430\u0436\u043d\u043e!<\/b> \u043e\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u2014 \u0442\u043e\u0447\u043a\u0443.<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0434\u0430\u043f\u0442\u0435\u0440, \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f Pong. \u042d\u0442\u043e\u0442 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0438\u0437\u0432\u043d\u0435 \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u0441\u0432\u043e\u0435\u043c\u0443 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044e, \u0440\u043e\u0432\u043d\u043e \u043a\u0430\u043a \u0438 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u0415\u0449\u0435 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443, \u0447\u0442\u043e \u043f\u043e \u0437\u0430\u0434\u0443\u043c\u043a\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432 \u043b\u0438\u0431\u044b \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0438 \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0435\u0435\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0412\u043e\u0442 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043e\u0442 \u043f\u0440\u043e\u0433\u0438 \u0432 D-Bus-\u043c\u0438\u0440:\n<pre><code class=\"cpp\">QObject::connect(this, SIGNAL(callingMe(QString,QString)), m_pongAdapter, SIGNAL(callingMe(QString, QString)));<\/code><\/pre>\n<p><b>\u0412\u0430\u0436\u043d\u043e!<\/b> \u0438\u043c\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430, \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0432 Q_ClASSINFO \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u0447\u043a\u0443.<\/li>\n<li>\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c Pong \u043f\u043e \u043d\u0435\u043a\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:\n<pre><code class=\"cpp\"> if( ! connection.registerObject(&quot;\/&quot;, &pong)){<\/code><\/pre>\n<p> <b>\u0412\u0430\u0436\u043d\u043e!<\/b> \u042d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b &#8212;<b>\/<\/b><\/li>\n<\/ol>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442 \u0432 \u044d\u0442\u043e\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0437\u043d\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043b\u043e \u0441\u043b\u043e\u0442, \u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 (Pong) \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 <b>QDbusContext<\/b>, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0430\u043b\u044f <i>message<\/i> \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u0440\u0433\u0430\u0442\u044c \u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0445\u043e\u0442\u0438\u043c \u0430\u0431\u0441\u0442\u0440\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 D-Bus \u0438 \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0433\u043e\u043b\u043e\u0432\u043d\u0443\u044e \u0431\u043e\u043b\u044c \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442, \u043d\u043e \u043f\u043e\u043a\u0430 \u0441 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430\u043c\u0438, \u0438\u043c \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u044b\u043c, \u044f \u043d\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f.<\/p>\n<p>  \u0418 \u0440\u0430\u0437 \u0443\u0436\u0435 \u0437\u0430\u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u0442\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c \u043e \u0441\u0435\u0440\u0434\u0446\u0435 \u0432\u0441\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f. \u0418 \u0441\u0435\u0440\u0434\u0446\u0435 \u044d\u0442\u043e \u0434\u0432\u0443\u0445\u043a\u0430\u043c\u0435\u0440\u043d\u043e\u0435: \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u0430\u043c\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e QDbusMessage \u0442.\u0435. \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u0441\u043b\u0430\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438, \u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u043a\u0430\u043c\u0435\u0440\u0430 \u044d\u0442\u043e \u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 QDbusArgument \u0438 QDbusReply. \u0412\u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043f\u043e\u0441\u043b\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a property \u0432 dbusviwer \u0441\u0434\u0435\u043b\u0430\u043d\u0430 \u0442\u0430\u043a: <\/p>\n<pre><code class=\"cpp\">QDBusMessage message = QDBusMessage::createMethodCall(sig.mService, sig.mPath, QLatin1String(&quot;org.freedesktop.DBus.Properties&quot;), QLatin1String(&quot;Get&quot;));     QList&lt;QVariant&gt; arguments;     arguments &lt;&lt; sig.mInterface &lt;&lt; sig.mName;     message.setArguments(arguments);     c.callWithCallback(message, this, SLOT(dumpMessage(QDBusMessage)));     QDBusInterface iface(sig.mService, sig.mPath, sig.mInterface,c);     if( !iface.isValid())         qDebug()&lt;&lt;(QDBusError(iface.lastError()).message());     else         qDebug()&lt;&lt;iface.property(sig.mName.toLatin1().data()); <\/code><\/pre>\n<p>  \u041d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0430\u043d\u0438\u0435 QDbusArgument. \u0414\u043b\u044f \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u0434\u0432\u0435 \u0432\u0435\u0449\u0438: \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b &gt;&gt; &lt;&lt;, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0442\u0438\u043f \u043d\u0435 \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 Qt:<\/p>\n<pre><code class=\"cpp\">struct TestStructure{     int id;     QString str; }; Q_DECLARE_METATYPE(TestStructure)  static QDBusArgument& operator &lt;&lt;(QDBusArgument &argument, const TestStructure & arg) {     argument.beginStructure();     argument&lt;&lt;arg.id&lt;&lt;arg.str;     argument.endStructure();     return argument; }<\/code><\/pre>\n<p>  \u0418 \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0437\u0432\u0430\u0442\u044c qDBusRegisterMetaType. \u0418 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f: \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <b>QDbusInterface<\/b> \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u043d\u0443\u0436\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 void-\u043c\u0435\u0442\u043e\u0434, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u043c \u0432\u0430\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <b>QDbusReply<\/b>.<br \/>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0441\u0435. \u0417\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043e, \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435 \u0433\u0434\u0435 \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/185950\/\"> http:\/\/habrahabr.ru\/post\/185950\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/habrahabr.ru\/post\/185212\/\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f<\/a> \u0447\u0430\u0441\u0442\u044c \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0430 \u043c\u0440\u0430\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b, \u043d\u043e \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e, \u0433\u043e\u0440\u0430\u0437\u0434\u043e, \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435.<\/p>\n<h5>\u0420\u0430\u0437\u0431\u043e\u0440 \u0431\u043e\u043d\u0443\u0441-\u043b\u0435\u0432\u0435\u043b\u0430<\/h5>\n<p>\u0418\u0442\u0430\u043a, \u0441\u043f\u0441\u0430\u0438\u0431\u043e \u0445\u0430\u0431\u0440\u0430\u0436\u0438\u0442\u0435\u043b\u044e \u043e\u043d \u043e\u0431\u0440\u0430\u0442\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 QDbusAbstractAdaptor \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c. \u0414\u043b\u044f \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u043e\u0432\u043e\u0441\u0442\u044c\u044e, \u0442.\u043a. \u044f \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u044b\u043a, \u0447\u0442\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0431\u044b\u0442\u044c. \u041c\u043e\u0436\u0435\u0442 \u044d\u0442\u043e \u0443\u0431\u0435\u0440\u0435\u0436\u0435\u0442 \u0435\u0449\u0435 \u043a\u043e\u0433\u043e-\u0442\u043e \u043e\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043b\u044f\u043f\u0430.<\/p>\n<p>  \u0412\u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043c\u043e\u0435 \u043d\u0435\u0437\u043d\u0430\u043d\u0438\u0435 \u043f\u0430\u0442\u0435\u0440\u043d\u043e\u0432, \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0442\u0435\u043d \u00ab\u0410\u0434\u0430\u043f\u0442\u0435\u0440\u00bb. \u0422\u0430\u043a \u0432\u043e\u0442 QAbstractAdaptor \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043e\u043d \u0438 \u0435\u0441\u0442\u044c. \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0438, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043b\u0438\u0431\u044b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-185950","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=185950"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185950\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}