Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, March 2007
Creating a DBus Adaptor from inside his object


Message 1 in thread

Hi,

Why if I instantiate a QDBusAbstractAdaptor object from *inside* the
object his referencing I cannot see the interface ?
Following the code.
If the symbol FROMINSIDE is NOT defined, the program works well:

happycactus@lama:~/Progetti/TecnoMare/Rotis2> qdbus
com.studiofuga.test /test
property read QString com.studiofuga.test.name
signal void com.studiofuga.test.crashed()
method QString com.studiofuga.test.getName()
method void com.studiofuga.test.ping()
method void com.studiofuga.test.setName(QString val)
method void com.studiofuga.test.test()
method QDBusVariant org.freedesktop.DBus.Properties.Get(QString
interface_name, QString property_name)
method void org.freedesktop.DBus.Properties.Set(QString interface_name,
QString property_name, QDBusVariant value)
method QString org.freedesktop.DBus.Introspectable.Introspect()

if the FROMINSIDE is defined, it doesn't work as expected:

happycactus@lama:~/Progetti/TecnoMare/Rotis2> qdbus
com.studiofuga.test /test
method QDBusVariant org.freedesktop.DBus.Properties.Get(QString
interface_name, QString property_name)
method void org.freedesktop.DBus.Properties.Set(QString interface_name,
QString property_name, QDBusVariant value)
method QString org.freedesktop.DBus.Introspectable.Introspect()

As you can see, the methods are missing.
I am wondering if I am missing something...
Thank you in advance!

Regards,

ing. Federico Fuga



-:- adaptor.hpp -:-

#ifndef ADAPTOR_HPP
#define ADAPTOR_HPP

#include <QDBusAbstractAdaptor>

class CObject : public QObject 
{
    Q_OBJECT;
public:
    CObject (QObject *parent = 0);

    virtual ~CObject ();
};

class CAdaptor : public QDBusAbstractAdaptor
{
    Q_OBJECT;

    Q_CLASSINFO("D-Bus Interface", "com.studiofuga.test");
    Q_PROPERTY (QString name READ name);

public:
    CAdaptor (QObject *parent = 0);
    virtual ~CAdaptor();

public:
    QString name() {
        return QString("sacd");
    }

 public Q_SLOTS:
    void test();
    void ping();
    QString getName() {
        return QString(n);
    }
    void setName (QString val) {
        n = val;
    }

Q_SIGNALS:
    void crashed();

protected:
    QString n;
};

#endif

-:- adaptor.cpp -:-

#include <adaptor.hpp>
#include <QCoreApplication>
#include <QDBusConnection>

CObject::CObject (QObject *par)
    : QObject (par)
{
#ifdef FROMINSIDE
    CAdaptor *ad = new CAdaptor (this);

    QDBusConnection::sessionBus().registerObject ("/test", ad);  
#endif
}

CObject::~CObject()
{
}

CAdaptor::CAdaptor (QObject *parent)
    : QDBusAbstractAdaptor (parent)
{
}

CAdaptor::~CAdaptor()
{
}

void CAdaptor::test()
{
    qDebug("%s",  __FUNCTION__);
}

void CAdaptor::ping()
{
    qDebug("%s",__FUNCTION__);
}

int main (int argc, char *argv[])
{    
    QCoreApplication app (argc, argv);
    CObject ob;

#ifndef FROMINSIDE
    qDebug ("Creating the adaptor from outside the object");
#else
    qDebug ("Creating the adaptor from inside the object");
#endif

#ifndef FROMINSIDE
    CAdaptor adapt(&ob);
#endif

    QDBusConnection::sessionBus().registerService
("com.studiofuga.test");

#ifndef FROMINSIDE
    QDBusConnection::sessionBus().registerObject ("/test", &ob);
#endif

    app.exec();
    return 0;
}

-:- adaptor.pro -:-

TARGET=adaptor

CONFIG += qdbus 
QT -= gui
QT += core debug xml


SOURCES = adaptor.cpp
HEADERS = adaptor.hpp

-:-

--
 [ signature omitted ] 

Message 2 in thread

On Fri, 2 Mar 2007 16:39:21 +0100
"ing. Federico Fuga" <fuga@xxxxxxxxxxxxxx> wrote:

>     QDBusConnection::sessionBus().registerObject ("/test", ad);  

Ok, Ok. I have spent three hours to solve this issue, before seeing 30
seconds after sending the post that I am registering the adaptor, NOT
the object he is referring to.
I really and urgently need a vacation.

Thank you again.

ing. Federico Fuga

--
 [ signature omitted ]