[Interest] Question about using QtDBus

Rogers Nate nate.rogers at raymondcorp.com
Tue Sep 2 22:05:04 CEST 2014


On 09/02/2014 03:00 PM, Thiago Macieira wrote:

On Tuesday 02 September 2014 18:53:59 Rogers Nate wrote:


That option doesn't seem to be available to me, or am I not calling it
correctly?  I tried a few different ways...

nrogers at nrogers-Precision-T1500:/media/nrogers/data/dev/projects/dbustest/Da
taProcess$ qdbuscpp2xml -A -i ServiceData.h -o ServiceData.xml
unknown option: "-i"
nrogers at nrogers-Precision-T1500:/media/nrogers/data/dev/projects/dbustest/Da
taProcess$ qdbuscpp2xml -A ServiceData.h -o ServiceData.xml -i
unknown option: "-i"
nrogers at nrogers-Precision-T1500:/media/nrogers/data/dev/projects/dbustest/Da
taProcess$ qdbuscpp2xml -i ServiceData.h -o ServiceData.xml
unknown option: "-i"
nrogers at nrogers-Precision-T1500:/media/nrogers/data/dev/projects/dbustest/Da
taProcess$ qdbuscpp2xml -V
qdbuscpp2xml version 0.1
D-Bus QObject-to-XML converter


Pass it to qdbusxml2cpp, not to qdbuscpp2xml.

qdbuscpp2xml can't deal with non-Qt types since it doesn't know what the type
will expand to.



I used qdbuscpp2xml to generate new adapter and interface files but I am still getting the same error...


QDBusError("org.freedesktop.DBus.Error.InvalidSignature", "Unexpected reply signature: got "", expected "a(ss)"")

I included all my updated example code below.  I wonder if it is compiling and linking with the new adapter and interface files or if it is still using the ones it is auto generating?  When I tried to add the new adapter and interface files to my project it gave complier warnings about duplicate definitions.  Do I have to somehow disable the auto generation of adapter and interface files so I can add the ones I manually created using qdbuscpp2xml?


Data Process...

------------------------- Begin main.cpp -------------------------
#include <qt5/QtCore/QCoreApplication>
#include <qt5/QtDBus/QtDBus>
#include "ServiceData.h"
#include "ServiceErrorLogData.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    ServiceErrorLogData::registerMetaType();

    ServiceData *serviceData = new ServiceData();
    Q_UNUSED(serviceData);

    return a.exec();
}
------------------------- End main.cpp -------------------------


------------------------ Begin ServiceData.cpp ---------------------
#include "ServiceData.h"

ServiceData::ServiceData(QObject *parent) : QObject(parent)
{
    initVariables();

    new ServiceDataAdaptor(this);
    QDBusConnection connection = QDBusConnection::systemBus();
    connection.registerObject("/ServiceData", this);
    connection.registerService("com.GDM.ServiceData");
}

void ServiceData::initVariables()
{
    ServiceErrorLogData tempData = ServiceErrorLogData("2/17    11:14:40a", "64 95%");
    m_ServiceErrorLog.append(tempData);
    ServiceErrorLogData tempData2 = ServiceErrorLogData("2/5    8:20:18a", "8L 53%");
    m_ServiceErrorLog.append(tempData2);
}

QList<ServiceErrorLogData> ServiceData::serviceErrorLog()
{
    return m_ServiceErrorLog;
}
-------------------------- End ServiceData.cpp ----------------------

------------------------ Begin ServiceData.h ------------------------
#ifndef SERVICEDATA_H
#define SERVICEDATA_H

#include <qt5/QtCore/QCoreApplication>
#include <qt5/QtDBus/QtDBus>
#include "ServiceErrorLogData.h"
#include "ServiceDataAdaptor.h"

class ServiceErrorLogData;

class ServiceData : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "com.GDM.ServiceData")

public:
    explicit ServiceData(QObject *parent = 0);

public slots:
    QList<ServiceErrorLogData> serviceErrorLog();

private:
    void initVariables();

    QList<ServiceErrorLogData> m_ServiceErrorLog;
};

Q_DECLARE_METATYPE(QList<ServiceErrorLogData>)

#endif // SERVICEDATA_H
------------------------- End ServiceData.h -------------------------


------------------- Begin ServiceErrorLogData.cpp -------------------
#include "ServiceErrorLogData.h"

ServiceErrorLogData::ServiceErrorLogData() :
        m_Label(),
        m_Value()
{
}

ServiceErrorLogData::ServiceErrorLogData(const QString &label, const QString &value) :
        m_Label(label),
        m_Value(value)
{
}

ServiceErrorLogData::ServiceErrorLogData(const ServiceErrorLogData &other) :
        m_Label(other.m_Label),
        m_Value(other.m_Value)
{
}

ServiceErrorLogData& ServiceErrorLogData::operator=(const ServiceErrorLogData &other)
{
    m_Label = other.m_Label;
    m_Value = other.m_Value;

    return *this;
}

ServiceErrorLogData::~ServiceErrorLogData()
{
}

QString ServiceErrorLogData::label() const
{
    return m_Label;
}

QString ServiceErrorLogData::value() const
{
    return m_Value;
}

void ServiceErrorLogData::registerMetaType()
{
    qRegisterMetaType<ServiceErrorLogData>("ServiceErrorLogData");
    qRegisterMetaType<QList<ServiceErrorLogData> >("QList<ServiceErrorLogData>");

    qDBusRegisterMetaType<ServiceErrorLogData>();
    qDBusRegisterMetaType<QList<ServiceErrorLogData> >();
}

QDBusArgument &operator<<(QDBusArgument &argument, const ServiceErrorLogData &logData)
{
    argument.beginStructure();
    argument << logData.m_Label;
    argument << logData.m_Value;
    argument.endStructure();

    return argument;
}

const QDBusArgument &operator>>(const QDBusArgument &argument, ServiceErrorLogData &logData)
{
    argument.beginStructure();
    argument >> logData.m_Label;
    argument >> logData.m_Value;
    argument.endStructure();

    return argument;
}
------------------- End ServiceErrorLogData.cpp -------------------

------------------ Begin ServiceErrorLogData.h ------------------
#ifndef SERVICEERRORLOGDATA_H
#define SERVICEERRORLOGDATA_H

#include <qt5/QtCore/QCoreApplication>
#include <qt5/QtDBus/QtDBus>

class ServiceErrorLogData
{

public:
    ServiceErrorLogData();
    ServiceErrorLogData(const QString &label, const QString &value);
    ServiceErrorLogData(const ServiceErrorLogData &other);
    ServiceErrorLogData& operator=(const ServiceErrorLogData &other);
    ~ServiceErrorLogData();

    friend QDBusArgument &operator<<(QDBusArgument &argument, const ServiceErrorLogData &logData);
    friend const QDBusArgument &operator>>(const QDBusArgument &argument, ServiceErrorLogData &logData);

    QString label() const;
    QString value() const;

    // Register ServiceErrorLogData with the Qt type system
    static void registerMetaType();

private:
    QString m_Label;
    QString m_Value;
};

Q_DECLARE_METATYPE(ServiceErrorLogData)

#endif // SERVICEERRORLOGDATA_H
------------------- End ServiceErrorLogData.h --------------------

-------------------- Begin ServiceData.xml -----------------------
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"<http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd>>
<node>
  <interface name="com.GDM.ServiceData">
    <method name="serviceErrorLog">
        <arg name="QList<ServiceErrorLogData>" type="a(ss)" direction="out"/>
        <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<ServiceErrorLogData>"/>
    </method>
  </interface>
</node>
-------------------- End ServiceData.h -----------------------

---------------- Begin com.GDM.ServiceData.conf -------------------
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"<http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd>>
<busconfig>
    <policy user="root">
        <allow own="com.GDM.ServiceData"/>
        <allow send_type="method_call" log="true"/>
    </policy>
    <policy context="default">
        <allow send_interface="com.GDM.ServiceData"/>
        <allow receive_sender="com.GDM.ServiceData"/>
        <allow receive_interface="com.GDM.ServiceData"/>
    </policy>
</busconfig>
---------------- End com.GDM.ServiceData.conf -------------------

------------------ Begin DataProcess.pro ---------------------
#-------------------------------------------------
#
# Project created by QtCreator 2014-07-16T11:59:31
#
#-------------------------------------------------

QT += dbus

DBUS_ADAPTORS += ServiceData.xml

QMAKE_LFLAGS_APP += -rdynamic

QT       += core
QT       -= gui

TARGET = Data
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

INCLUDEPATH += \
    $${OUT_PWD}/../Data/

SOURCES += main.cpp \
    ServiceData.cpp \
    ServiceErrorLogData.cpp

HEADERS += \
    ServiceData.h \
    ServiceErrorLogData.h

OTHER_FILES += \
    ServiceData.xml

# Install the dbus system config file
application_interfaces.path = /etc/dbus-1/system.d/
application_interfaces.files = com.GDM.ServiceData.conf
INSTALLS += application_interfaces

# install
target.path = /opt/dbustest
INSTALLS += target

------------------- End DataProcess.pro ----------------------

------------------- Begin ServiceDataAdaptor.cpp ----------------------
/*
 * This file was generated by qdbusxml2cpp version 0.7
 * Command line was: qdbusxml2cpp ServiceData.xml -i ServiceData.h -a ServiceDataAdaptor
 *
 * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 *
 * This is an auto-generated file.
 * Do not edit! All changes made to it will be lost.
 */

#include "ServiceDataAdaptor.h"
#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

/*
 * Implementation of adaptor class ServiceDataAdaptor
 */

ServiceDataAdaptor::ServiceDataAdaptor(QObject *parent)
    : QDBusAbstractAdaptor(parent)
{
    // constructor
    setAutoRelaySignals(true);
}

ServiceDataAdaptor::~ServiceDataAdaptor()
{
    // destructor
}

void ServiceDataAdaptor::serviceErrorLog()
{
    // handle method call com.GDM.ServiceData.serviceErrorLog
    QMetaObject::invokeMethod(parent(), "serviceErrorLog");
}
------------------- End ServiceDataAdaptor.cpp ----------------------

------------------- Begin ServiceDataAdaptor.h ----------------------
/*
 * This file was generated by qdbusxml2cpp version 0.7
 * Command line was: qdbusxml2cpp ServiceData.xml -i ServiceData.h -a ServiceDataAdaptor
 *
 * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 *
 * This is an auto-generated file.
 * This file may have been hand-edited. Look for HAND-EDIT comments
 * before re-generating it.
 */

#ifndef SERVICEDATAADAPTOR_H_1409684640
#define SERVICEDATAADAPTOR_H_1409684640

#include <QtCore/QObject>
#include <QtDBus/QtDBus>
#include "ServiceData.h"
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;

/*
 * Adaptor class for interface com.GDM.ServiceData
 */
class ServiceDataAdaptor: public QDBusAbstractAdaptor
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "com.GDM.ServiceData")
    Q_CLASSINFO("D-Bus Introspection", ""
"  <interface name=\"com.GDM.ServiceData\">\n"
"    <method name=\"serviceErrorLog\"/>\n"
"  </interface>\n"
        "")
public:
    ServiceDataAdaptor(QObject *parent);
    virtual ~ServiceDataAdaptor();

public: // PROPERTIES
public Q_SLOTS: // METHODS
    void serviceErrorLog();
Q_SIGNALS: // SIGNALS
};

#endif
------------------- End ServiceDataAdaptor.h ----------------------

------------------- Begin ServiceDataInterface.cpp ----------------------
/*
 * This file was generated by qdbusxml2cpp version 0.7
 * Command line was: qdbusxml2cpp ServiceData.xml -i ServiceData.h -p ServiceDataInterface
 *
 * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 *
 * This is an auto-generated file.
 * This file may have been hand-edited. Look for HAND-EDIT comments
 * before re-generating it.
 */

#include "ServiceDataInterface.h"

/*
 * Implementation of interface class ComGDMServiceDataInterface
 */

ComGDMServiceDataInterface::ComGDMServiceDataInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
    : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
{
}

ComGDMServiceDataInterface::~ComGDMServiceDataInterface()
{
}

------------------- End ServiceDataInterface.cpp ----------------------

------------------- Begin ServiceDataInterface.h ----------------------
/*
 * This file was generated by qdbusxml2cpp version 0.7
 * Command line was: qdbusxml2cpp ServiceData.xml -i ServiceData.h -p ServiceDataInterface
 *
 * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 *
 * This is an auto-generated file.
 * Do not edit! All changes made to it will be lost.
 */

#ifndef SERVICEDATAINTERFACE_H_1409684768
#define SERVICEDATAINTERFACE_H_1409684768

#include <QtCore/QObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtDBus/QtDBus>
#include "ServiceData.h"

/*
 * Proxy class for interface com.GDM.ServiceData
 */
class ComGDMServiceDataInterface: public QDBusAbstractInterface
{
    Q_OBJECT
public:
    static inline const char *staticInterfaceName()
    { return "com.GDM.ServiceData"; }

public:
    ComGDMServiceDataInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);

    ~ComGDMServiceDataInterface();

public Q_SLOTS: // METHODS
    inline QDBusPendingReply<> serviceErrorLog()
    {
        QList<QVariant> argumentList;
        return asyncCallWithArgumentList(QLatin1String("serviceErrorLog"), argumentList);
    }

Q_SIGNALS: // SIGNALS
};

namespace com {
  namespace GDM {
    typedef ::ComGDMServiceDataInterface ServiceData;
  }
}
#endif
------------------- End ServiceDataInterface.h ----------------------

Comm Process...

------------------------- Begin main.cpp -------------------------
#include <qt5/QtCore/QCoreApplication>
#include <qt5/QtDBus/QtDBus>

#include "CanData.h"
#include "ServiceErrorLogData.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    ServiceErrorLogData::registerMetaType();

    CanData *canData = new CanData();
    Q_UNUSED(canData);

    return a.exec();
}
------------------------- End main.cpp -------------------------


------------------------ Begin CanData.cpp ------------------------
#include <qt5/QtCore/QCoreApplication>
#include <qt5/QtDBus/QtDBus>
#include "CanData.h"
#include "ServiceErrorLogData.h"

CanData::CanData(QObject *parent) : QObject(parent)
{
    m_ServiceData = new com::GDM::ServiceData("com.GDM.ServiceData", "/ServiceData", QDBusConnection::systemBus(), this);

    // Setup the timer
    m_Timer = new QTimer(this);
    connect(m_Timer, SIGNAL(timeout()), this, SLOT(generateTestData()));
    m_Timer->start(800);
}

void CanData::generateTestData()
{
    QDBusPendingReply<QList<ServiceErrorLogData> > logData = m_ServiceData->serviceErrorLog();
    logData.waitForFinished();
    if (logData.isError())
    {
        qDebug() << logData.error();
    }
    QList<ServiceErrorLogData> tempData = logData.value();
    qDebug() << "Log Data Count: " << tempData.count();
}
------------------------ End CanData.cpp ------------------------

------------------------ Begin CanData.h ------------------------
#ifndef CANDATA_H
#define CANDATA_H

#include <qt5/QtDBus/QtDBus>
#include "ServiceDataInterface.h"

class CanData : public QObject
{
    Q_OBJECT

public:
    explicit CanData(QObject *parent = 0);

private slots:
    void generateTestData();

private:
    com::GDM::ServiceData *m_ServiceData;
    QTimer *m_Timer;
};

#endif // CANDATA_H
------------------------ End CanData.h ------------------------

---------------------- Begin CommProcess.pro ---------------------
#-------------------------------------------------
#
# Project created by QtCreator 2014-04-18T09:19:20
#
#-------------------------------------------------

QT += dbus

DBUS_INTERFACES += ../DataProcess/ServiceData.xml

QMAKE_LFLAGS_APP += -rdynamic

QT       += core
QT       -= gui

TARGET = CanComm
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

INCLUDEPATH += \
    ../DataProcess/ \
    $${OUT_PWD}/../CanComm/ \
    $${OUT_PWD}/../Data/

SOURCES += main.cpp \
    CanData.cpp \
    ../DataProcess/ServiceErrorLogData.cpp

HEADERS += \
    CanData.h \
    ../DataProcess/ServiceErrorLogData.h

# install
target.path = /opt/dbustest
INSTALLS += target
---------------------- End CommProcess.pro ---------------------


Top level project file...

---------------------- Begin dbustest.pro ---------------------
TEMPLATE = subdirs

SUBDIRS += \
    DataProcess/DataProcess.pro \
    CommProcess/CommProcess.pro
---------------------- End dbustest.pro ---------------------


Nate


Confidentiality Notice: The preceding e-mail message (including any attachments) contains information that may be confidential, protected by applicable legal privileges, or constitute non-public information. It is intended to be conveyed only to the designated recipient(s). If you are not an intended recipient of this message, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution or reproduction of this message by unintended recipients is not authorized and may be unlawful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140902/74b674c5/attachment.html>


More information about the Interest mailing list