diff --git a/src/kdbusservice.h b/src/kdbusservice.h --- a/src/kdbusservice.h +++ b/src/kdbusservice.h @@ -115,7 +115,17 @@ * The exit value of a @c Unique instance can be set from the running * instance with setExitValue(), the default value is @c 0. */ - NoExitOnFailure = 4 + NoExitOnFailure = 4, + /** + * Indicates that if there's already a unique service running, to be quit and replaced + * with our own. + * + * If exported, it will try first quitting the service calling org.qtproject.Qt.QCoreApplication.quit, + * which is exported by @class KDBusService by default. + * + * @since 5.65 + */ + Replace = 8 }; Q_ENUM(StartupOption) diff --git a/src/kdbusservice.cpp b/src/kdbusservice.cpp --- a/src/kdbusservice.cpp +++ b/src/kdbusservice.cpp @@ -196,7 +196,14 @@ return; } - if (options & KDBusService::Unique) { + if (options & KDBusService::Replace) { + auto message = QDBusMessage::createMethodCall(d->serviceName, + QStringLiteral("/MainApplication"), + QStringLiteral("org.qtproject.Qt.QCoreApplication"), + QStringLiteral("quit")); + QDBusConnection::sessionBus().asyncCall(message); + waitForRegistration(); + } else if (options & KDBusService::Unique) { // Already running so it's ok! QVariantMap platform_data; platform_data.insert(QStringLiteral("desktop-startup-id"), QString::fromUtf8(qgetenv("DESKTOP_STARTUP_ID")));