diff --git a/src/main.cpp b/src/main.cpp index 953c69ee2d..3c8b01838f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -529,7 +529,9 @@ int main(int argc, char* argv[]) req.addSaveTask(); } } - return requestCaptureAndWait(req); + int guiExitCode = requestCaptureAndWait(req); + delete qApp; + return guiExitCode; } else if (parser.isSet(fullArgument)) { // FULL reinitializeAsQApplication(argc, argv, translator, qtTranslator); @@ -564,7 +566,11 @@ int main(int argc, char* argv[]) if (!clipboard && path.isEmpty() && !raw && !upload) { req.addSaveTask(); } - return requestCaptureAndWait(req); + { + int fullExitCode = requestCaptureAndWait(req); + delete qApp; + return fullExitCode; + } } else if (parser.isSet(screenArgument)) { // SCREEN reinitializeAsQApplication(argc, argv, translator, qtTranslator); @@ -614,7 +620,11 @@ int main(int argc, char* argv[]) req.addSaveTask(); } - return requestCaptureAndWait(req); + { + int screenExitCode = requestCaptureAndWait(req); + delete qApp; + return screenExitCode; + } } else if (parser.isSet(configArgument)) { // CONFIG bool autostart = parser.isSet(autostartOption); bool notification = parser.isSet(notificationOption); @@ -680,6 +690,6 @@ int main(int argc, char* argv[]) } } finish: - + delete qApp; return 0; } diff --git a/src/utils/valuehandler.cpp b/src/utils/valuehandler.cpp index 99c2bbe1da..fbd4bb502b 100644 --- a/src/utils/valuehandler.cpp +++ b/src/utils/valuehandler.cpp @@ -530,11 +530,15 @@ bool Region::check(const QVariant& val) QVariant Region::process(const QVariant& val) { - // FIXME: This is temporary, just before D-Bus is removed + // Create a temporary QApplication if there is no global Qt application + // instance at all. Creating one while a QCoreApplication already exists + // is forbidden by Qt: the second constructor aborts early, but its + // destructor still runs and corrupts global state (e.g. Wayland + // connections), causing subsequent portal calls to hang. auto argv = std::make_unique(1); auto argc = std::make_unique(0); std::unique_ptr tempApp; - if (QGuiApplication::screens().empty()) { + if (!QCoreApplication::instance()) { tempApp = std::make_unique(*argc, argv.get()); }