[Interest] Question about using QtDBus

Rogers Nate nate.rogers at raymondcorp.com
Wed Sep 3 18:26:31 CEST 2014


On 09/03/2014 12:17 PM, Thiago Macieira wrote:
> On Wednesday 03 September 2014 15:03:05 Rogers Nate wrote:
>> QDBusError("org.freedesktop.DBus.Error.InvalidSignature", "Unexpected reply
>> signature: got "", expected "a(ss)"")
> This means the interface code knows that the reply should contain an array of 
> a structure containing a pair of strings, but the reply did not have that.
>
> Can you attach your generated adaptor file and your actual called function?


Here is the generated file...


------------------- Begin ServiceDataAdaptor.cpp ----------------------
/*
 * This file was generated by qdbusxml2cpp version 0.7
 * Command line was: qdbusxml2cpp ServiceData.xml -i ServiceData.h -i
ServiceErrorLogData.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 -i
ServiceErrorLogData.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_1409751106
#define SERVICEDATAADAPTOR_H_1409751106

#include <QtCore/QObject>
#include <QtDBus/QtDBus>
#include "ServiceData.h"
#include "ServiceErrorLogData.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 ----------------------






Here is the Service Data class that stores the array of objects I want
to return...


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

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

    new ServiceDataAdaptor(this);
    QDBusConnection connection = QDBusConnection::systemBus();

    if (!connection.interface()->isServiceRegistered("com.GDM.ServiceData"))
    {
        if (!connection.registerService("com.GDM.ServiceData"))
        {
            qFatal("Could not register com.GDM.ServiceData service!");
        }

        if (!connection.registerObject("/ServiceData", this))
        {
            qFatal("Could not register ServiceData object!");
        }
    }
}

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 -------------------------





Here is the process that is using the dbus interface to try and retrieve
the array of objects...


------------------------ 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 ------------------------


Not sure if that is everything you wanted to see, or if it was too much
information.  Anyway, thanks again for the help!

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.




More information about the Interest mailing list