diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-12-15 18:50:01 +0100 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2011-03-29 12:30:12 +0200 |
commit | e2f060294c1f9707fed48c532ba7de382efe3925 (patch) | |
tree | b1441fa86d9cd70a94c2836b3ed17772bd9bd1da | |
parent | a0690166164b7feb059164d2b587ed54fa675485 (diff) | |
download | qt4-tools-e2f060294c1f9707fed48c532ba7de382efe3925.tar.gz |
Move the main D-Bus session and system connections to the main thread
Some applications experience weird behaviour that sometimes it works and
sometimes it doesn't, due to D-Bus being first used in a thread. So
instead do everything in the main thread for the two main connections.
-rw-r--r-- | src/dbus/qdbusconnection.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index fe7f41e44a..1fb11bcbb9 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -42,6 +42,7 @@ #include <qdebug.h> #include <qcoreapplication.h> #include <qstringlist.h> +#include <qthread.h> #include "qdbusconnection.h" #include "qdbusconnectioninterface.h" @@ -987,7 +988,16 @@ class QDBusDefaultConnection: public QDBusConnection public: inline QDBusDefaultConnection(BusType type, const char *name) : QDBusConnection(connectToBus(type, QString::fromLatin1(name))), ownName(name) - { } + { + // make sure this connection is running on the main thread + QCoreApplication *instance = QCoreApplication::instance(); + if (!instance) { + qWarning("QDBusConnection: %s D-Bus connection created before QCoreApplication. Application may misbehave.", + type == SessionBus ? "session" : type == SystemBus ? "system" : "generic"); + } else { + QDBusConnectionPrivate::d(*this)->moveToThread(instance->thread()); + } + } inline ~QDBusDefaultConnection() { disconnectFromBus(QString::fromLatin1(ownName)); } |