summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-12-15 17:50:01 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2011-03-29 10:30:12 (GMT)
commite2f060294c1f9707fed48c532ba7de382efe3925 (patch)
treeb1441fa86d9cd70a94c2836b3ed17772bd9bd1da /src/dbus
parenta0690166164b7feb059164d2b587ed54fa675485 (diff)
downloadQt-e2f060294c1f9707fed48c532ba7de382efe3925.zip
Qt-e2f060294c1f9707fed48c532ba7de382efe3925.tar.gz
Qt-e2f060294c1f9707fed48c532ba7de382efe3925.tar.bz2
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.
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusconnection.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp
index fe7f41e..1fb11bc 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)); }