[QDbus] Using more object in the same service



  • Hi, i want register more object on the same service in qdbus. I create two class.
    The first create the service name and the object One:
    @
    //First Object Manager (One Class)

    QDBusConnection connection = QDBusConnection::sessionBus();
    connection.registerService("aa.bb.cc");
    qDebug() << "register" << connection.registerObject("/One", this);
    @

    The second create the object Second:
    @
    //Second Object Interface (Interface Class)
    QDBusConnection connection = = QDBusConnection::sessionBus();
    qDebug() << connection.isConnected();
    qDebug() << "register" << connection.registerObject("/Second", this);
    @

    The problem is the second class return true but i can't see the Second object on dbus i only see the First. For me the problem is how qt can know where is the service name where Second object is register. But how can i do this?

    PS: if i put on every class the code
    @
    QDBusConnection connection = QDBusConnection::sessionBus();
    connection.registerService("aa.bb.cc");
    @
    I know that is wrong becaus only the first class called can register the service name. But in this case the only object register is the first class i called. If i run First class at the begin...first object is create. If i run Second class at the begin second object is create.



  • You can't :)
    Every class have their connection. You can add more object on the same connection. But you can't add an object on another connection.
    The only solution is create a connection for every class in the example you can create

    @
    //First Object
    QDBusConnection connection = QDBusConnection::sessionBus();
    connection.registerService("aa.bb.cc.One");
    qDebug() << "register" << connection.registerObject("/One", this);
    @

    @
    //Second Object
    QDBusConnection connection = QDBusConnection::sessionBus();
    connection.registerService("aa.bb.cc.Second");
    qDebug() << "register" << connection.registerObject("/Second", this);
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.