Results 1 to 3 of 3

Thread: QDBusInterface is blocking dbus

  1. #1
    Join Date
    Mar 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDBusInterface is blocking dbus

    Hi all,

    I am currently trying to implement a process using QtDBus. I successfully register a service and object on dbus. But then when I use QDBusInterface, dbus seems to be blocked on Introspect message as shown by dbus-monitor traces:
    Qt Code:
    1. method call sender=:1.363 -> dest=org.freedesktop.DBus serial=3 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetNameOwner
    2. string "my.test.test"
    3. method call sender=:1.363 -> dest=my.test.test serial=4 path=/; interface=org.freedesktop.DBus.Introspectable; member=Introspect
    To copy to clipboard, switch view to plain text mode 

    It seems to be a regular problem with QtDbus as shown by following posts:
    http://www.qtcentre.org/threads/3699...-blocking-dbus
    https://bugreports.qt-project.org/browse/QTBUG-14485

    I have tried to use QDbusConnection::asyncCall() to remove DBusInterface. In this use case, the message is correctly sent on DBus but it is never received.

    In conclusion, I was not able to find a correct solution to my problem, so I hope someone here can help me find a way out, thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QDBusInterface is blocking dbus

    You seem to have forgotten to post any code of your application.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBusInterface is blocking dbus

    Sorry, here is some pieces of code :

    I use Dbus in a QThread to use its own even loop (As I implement a library, I don't want any blocking call, such exec(), in the main thread).
    So, I initialize it in this way:
    Qt Code:
    1. Worker::Worker()
    2. {
    3. moveToThread(_thread);
    4. _dbus = new DbusHandler();
    5. _dbus->moveToThread(_thread);
    6. _thread->start();
    7.  
    8. connect(_thread, SIGNAL(started()), _dbus, SLOT(initializeDBus()));
    9. connect(this, SIGNAL(sig_send(const QString)), _dbus, SLOT(send(const QString)));
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void DBusHandler::initializeDBus()
    2. {
    3. QDBusConnection _connection = QDBusConnection::sessionBus();
    4.  
    5. if ( ! _connection.isConnected())
    6. throw runtime_error("Could not connect to DBUS.");
    7.  
    8. // register the serviceName
    9. if ( not _connection.registerService(serviceName) )
    10. throw runtime_error("Could not register the service using QDBusConnection::registerService");
    11.  
    12. // register the current object to the path "/"
    13. if ( not _connection.registerObject("/", this, QDBusConnection::ExportAllSlots))
    14. throw runtime_error("Could not register object using QDBusConnection::registerObject");
    15. }
    To copy to clipboard, switch view to plain text mode 
    Then I send the message on Dbus using the same thread using this slot connected to the signal sig_send() of a Worker class (which is in the same thread).
    Qt Code:
    1. void DBusHandler::send(const QString message)
    2. {
    3. QDBusInterface interface(serviceName, "/", "", QDBusConnection::sessionBus());
    4.  
    5. interface.asyncCall(serviceName, message);
    6. }
    To copy to clipboard, switch view to plain text mode 
    This method allows to emit sig_send signal and send the message to the above method.
    Qt Code:
    1. void Worker::send(const QString message)
    2. {
    3. emit sig_send(message);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Finally my main is:
    Qt Code:
    1. int main(int , char** )
    2. {
    3. Worker* worker = new Worker();
    4. while(true)
    5. worker->send("Hello world!");
    6. }
    To copy to clipboard, switch view to plain text mode 
    With this code, Dbus is blocking on QDBusInterface introspection (as explained in the previous post)
    Strangely, this code seems to work well with Qt 4.6.2 but not with Qt 4.8.4. More amazingly, it works also if I remove the infinite loop in the main and send only one message.
    Does anyone have a solution or an explanation to this problem?

    Thanks in advance.

Similar Threads

  1. Blocking the app
    By Alundra in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2013, 04:18
  2. QDBusInterface blocking dbus
    By zengtao in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2012, 16:39
  3. Qt 4.5.0 win opensource and <dbus/dbus.h>
    By YaK in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd March 2009, 12:06
  4. DBus and IPC
    By DrDonut in forum Qt Programming
    Replies: 3
    Last Post: 23rd March 2008, 00:42
  5. Blocking ftp
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2007, 09:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.