SingleApplication: Only create an DBus adaptor when needed
authorLuís Pereira <luis.artur.pereira@gmail.com>
Tue, 31 May 2016 20:34:48 +0000 (21:34 +0100)
committerLuís Pereira <luis.artur.pereira@gmail.com>
Tue, 31 May 2016 20:34:48 +0000 (21:34 +0100)
Save an allocation and helps static analyzers.

lxqtsingleapplication.cpp

index 90a351b..0e0ea57 100644 (file)
@@ -43,7 +43,6 @@ SingleApplication::SingleApplication(int &argc, char **argv, StartOptions option
     QString service =
         QString::fromLatin1("org.lxqt.%1").arg(QApplication::applicationName());
 
     QString service =
         QString::fromLatin1("org.lxqt.%1").arg(QApplication::applicationName());
 
-    SingleApplicationAdaptor *mAdaptor = new SingleApplicationAdaptor(this);
     QDBusConnection bus = QDBusConnection::sessionBus();
 
     if (!bus.isConnected()) {
     QDBusConnection bus = QDBusConnection::sessionBus();
 
     if (!bus.isConnected()) {
@@ -65,6 +64,7 @@ SingleApplication::SingleApplication(int &argc, char **argv, StartOptions option
     bool registered = (bus.registerService(service) ==
                        QDBusConnectionInterface::ServiceRegistered);
     if (registered) { // We are the primary instance
     bool registered = (bus.registerService(service) ==
                        QDBusConnectionInterface::ServiceRegistered);
     if (registered) { // We are the primary instance
+        SingleApplicationAdaptor *mAdaptor = new SingleApplicationAdaptor(this);
         QLatin1String objectPath("/");
         bus.registerObject(objectPath, mAdaptor,
             QDBusConnection::ExportAllSlots);
         QLatin1String objectPath("/");
         bus.registerObject(objectPath, mAdaptor,
             QDBusConnection::ExportAllSlots);