diff --git a/src/gui/platform/unix/qgnometheme.cpp b/src/gui/platform/unix/qgnometheme.cpp index c70c3580185..aafaff3732b 100644 --- a/src/gui/platform/unix/qgnometheme.cpp +++ b/src/gui/platform/unix/qgnometheme.cpp @@ -66,15 +66,14 @@ QGnomeThemePrivate::QGnomeThemePrivate() message.setArguments({}); message << appearanceNamespace << contrastKey; - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(dbus.asyncCall(message)); - QObject::connect(watcher, &QDBusPendingCallWatcher::finished, watcher, [this](QDBusPendingCallWatcher *watcher) { + pendingCallWatcher = std::make_unique(dbus.asyncCall(message)); + QObject::connect(pendingCallWatcher.get(), &QDBusPendingCallWatcher::finished, pendingCallWatcher.get(), [this](QDBusPendingCallWatcher *watcher) { if (!watcher->isError()) { QDBusPendingReply reply = *watcher; if (Q_LIKELY(reply.isValid())) updateHighContrast(static_cast(reply.value().toUInt())); } initDbus(); - watcher->deleteLater(); }); } else { qCWarning(lcQpaThemeGnome) << "dbus connection failed. Last error: " << dbus.lastError(); diff --git a/src/gui/platform/unix/qgnometheme_p.h b/src/gui/platform/unix/qgnometheme_p.h index 08bba609875..41df765eccf 100644 --- a/src/gui/platform/unix/qgnometheme_p.h +++ b/src/gui/platform/unix/qgnometheme_p.h @@ -24,6 +24,7 @@ QT_BEGIN_NAMESPACE class QGnomeThemePrivate; #if QT_CONFIG(dbus) class QDBusListener; +class QDBusPendingCallWatcher; #endif class Q_GUI_EXPORT QGnomeTheme : public QGenericUnixTheme @@ -66,6 +67,7 @@ public: Qt::ContrastPreference m_contrast = Qt::ContrastPreference::NoPreference; private: std::unique_ptr dbus; + std::unique_ptr pendingCallWatcher; bool initDbus(); void updateColorScheme(const QString &themeName); void updateHighContrast(Qt::ContrastPreference contrast);