plugin/bearer remove static QDBusConnection::systemBus() initialization

The static initialization of QDBusConnection::systemBus() can occur
before the creation of QCoreApplication. This causes a warning from
QDBusConnection and may cause the application to crash on exit.

Since QDBusConnection::systemBus() is just an accessor, there is no
real advantage to storing a static reference to it.

Task-number: QTBUG-39248
Change-Id: I4401810c7c2ffd21a30f9ffd41b3a46e7e09214c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
This commit is contained in:
Dyami Caliri 2014-05-24 10:18:48 -07:00 committed by The Qt Project
parent 50491efb0e
commit 8917179b47

View File

@ -58,8 +58,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
static QDBusConnection dbusConnection = QDBusConnection::systemBus();
class QNetworkManagerInterfacePrivate class QNetworkManagerInterfacePrivate
{ {
public: public:
@ -74,7 +72,7 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent)
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
QLatin1String(NM_DBUS_PATH), QLatin1String(NM_DBUS_PATH),
QLatin1String(NM_DBUS_INTERFACE), QLatin1String(NM_DBUS_INTERFACE),
dbusConnection); QDBusConnection::systemBus());
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -103,6 +101,9 @@ bool QNetworkManagerInterface::setConnections()
{ {
if(!isValid() ) if(!isValid() )
return false; return false;
QDBusConnection dbusConnection = QDBusConnection::systemBus();
bool allOk = false; bool allOk = false;
if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
QLatin1String(NM_DBUS_PATH), QLatin1String(NM_DBUS_PATH),
@ -198,7 +199,7 @@ QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const Q
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
dbusConnection); QDBusConnection::systemBus());
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -229,7 +230,7 @@ bool QNetworkManagerInterfaceAccessPoint::setConnections()
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)), connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>))); this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
QLatin1String("PropertiesChanged"), QLatin1String("PropertiesChanged"),
@ -306,7 +307,7 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_DEVICE), QLatin1String(NM_DBUS_INTERFACE_DEVICE),
dbusConnection); QDBusConnection::systemBus());
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -335,7 +336,7 @@ bool QNetworkManagerInterfaceDevice::setConnections()
nmDBusHelper = new QNmDBusHelper(this); nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)), connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)),
this, SIGNAL(stateChanged(QString,quint32))); this, SIGNAL(stateChanged(QString,quint32)));
if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_DEVICE), QLatin1String(NM_DBUS_INTERFACE_DEVICE),
QLatin1String("StateChanged"), QLatin1String("StateChanged"),
@ -397,7 +398,7 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
dbusConnection, parent); QDBusConnection::systemBus(), parent);
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -428,7 +429,7 @@ bool QNetworkManagerInterfaceDeviceWired::setConnections()
nmDBusHelper = new QNmDBusHelper(this); nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)), connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>))); this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
QLatin1String("PropertiesChanged"), QLatin1String("PropertiesChanged"),
@ -474,7 +475,7 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
dbusConnection, parent); QDBusConnection::systemBus(), parent);
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -498,6 +499,7 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections()
if(!isValid() ) if(!isValid() )
return false; return false;
QDBusConnection dbusConnection = QDBusConnection::systemBus();
bool allOk = false; bool allOk = false;
delete nmDBusHelper; delete nmDBusHelper;
nmDBusHelper = new QNmDBusHelper(this); nmDBusHelper = new QNmDBusHelper(this);
@ -591,7 +593,7 @@ QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService,
d->connectionInterface = new QDBusInterface(settingsService, d->connectionInterface = new QDBusInterface(settingsService,
QLatin1String(NM_DBUS_PATH_SETTINGS), QLatin1String(NM_DBUS_PATH_SETTINGS),
QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String(NM_DBUS_IFACE_SETTINGS),
dbusConnection); QDBusConnection::systemBus());
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -614,7 +616,7 @@ bool QNetworkManagerSettings::setConnections()
{ {
bool allOk = false; bool allOk = false;
if (!dbusConnection.connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS), if (!QDBusConnection::systemBus().connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS),
QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"), QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"),
this, SIGNAL(newConnection(QDBusObjectPath)))) { this, SIGNAL(newConnection(QDBusObjectPath)))) {
allOk = true; allOk = true;
@ -655,7 +657,7 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri
d->connectionInterface = new QDBusInterface(settingsService, d->connectionInterface = new QDBusInterface(settingsService,
d->path, d->path,
QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION),
dbusConnection, parent); QDBusConnection::systemBus(), parent);
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -681,6 +683,7 @@ bool QNetworkManagerSettingsConnection::setConnections()
if(!isValid() ) if(!isValid() )
return false; return false;
QDBusConnection dbusConnection = QDBusConnection::systemBus();
bool allOk = false; bool allOk = false;
if(!dbusConnection.connect(d->service, d->path, if(!dbusConnection.connect(d->service, d->path,
QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"), QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"),
@ -808,7 +811,7 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
dbusConnection, parent); QDBusConnection::systemBus(), parent);
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;
@ -837,7 +840,7 @@ bool QNetworkManagerConnectionActive::setConnections()
nmDBusHelper = new QNmDBusHelper(this); nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)), connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>))); this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
QLatin1String("PropertiesChanged"), QLatin1String("PropertiesChanged"),
@ -902,7 +905,7 @@ QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectP
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path, d->path,
QLatin1String(NM_DBUS_INTERFACE_IP4_CONFIG), QLatin1String(NM_DBUS_INTERFACE_IP4_CONFIG),
dbusConnection, parent); QDBusConnection::systemBus(), parent);
if (!d->connectionInterface->isValid()) { if (!d->connectionInterface->isValid()) {
d->valid = false; d->valid = false;
return; return;