Cannot receive response from DBus



  • I'm creating a custom service and object using QDbus and I'm using D-feet for testing purposes. I noticed that if I put all code in the main class, all works fine, otherwise it crashes.
    This works, I can see the service and the object correctly created with d-feet:

    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QDBusConnection session = QDBusConnection::sessionBus();
        QString myService = QString("test.example");
        QDBusObjectPath agentPath = QDBusObjectPath("/testagent");
        OrgBluezAgent1Interface* agent = new OrgBluezAgent1Interface(myService,agentPath.path(),session);
        Agent1Adaptor adaptor(agent);
        cout << "register service "<<boolalpha<<session.registerService(myService)<<endl;
        cout << "register object " <<boolalpha<<session.registerObject(agentPath.path(),agent)<<endl;
    
    
        //busTest b;
        return a.exec();
    }
    

    This is the not working version, in particular, D-feet crashes when I try to click on the service created with the following error: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying.

    busTest::busTest(QObject *parent)
        :   QObject(parent),bus(QDBusConnection::systemBus())
    {
        QDBusConnection session = QDBusConnection::sessionBus();
        QString myService = QString("test.example");
        QDBusObjectPath agentPath = QDBusObjectPath("/testagent");
        OrgBluezAgent1Interface* agent = new OrgBluezAgent1Interface(myService,agentPath.path(),session);
        Agent1Adaptor adaptor(agent);
        cout << "register service "<<boolalpha<<session.registerService(myService)<<endl;
        cout << "register object " <<boolalpha<<session.registerObject(agentPath.path(),agent)<<endl;
    }
    

    I'm also monitoring the dbus messages with dbus-monitor --session
    but I cannot find a suitable solution, it seems that something is destroyed in the busTest class and so I cannot receive the dbus response. Thanks


  • Lifetime Qt Champion

    Hi,

    Why are you getting both the system and session bus ?

    Your Agent1Adaptor object will be destroyed at the end of the constructor.



  • @SGaist You're right,I did not think about it! I have to remove the systemBus, I'm not using it in reality, it's part of the project that I found on Github. Ok then I can try to make it an instance variable of the class or similer. Thank you!


Log in to reply
 

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