From fb42ad5c25a3a095e3816112ef4a2921bb953631 Mon Sep 17 00:00:00 2001 From: Alaskra <958328065@qq.com> Date: Fri, 10 Jun 2022 21:46:21 +0800 Subject: [PATCH] fix unexpected close when launch external app (#2617) * fix unexpected close when launch external app * update --- src/core/flameshot.cpp | 6 ++++++ src/main.cpp | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index 26e95b94..cf112d79 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -411,6 +411,12 @@ void Flameshot::exportCapture(QPixmap capture, if (!(tasks & CR::UPLOAD)) { emit captureTaken(capture); } + // hacks: close a window to trigger qt's quitOnLastWindowClose + // if not create tmp_window and close, the `flameshot gui` won't exit after + // click copy button + QWidget* tmp = new QWidget(); + tmp->show(); + tmp->close(); } // STATIC ATTRIBUTES diff --git a/src/main.cpp b/src/main.cpp index 86d7a1c5..62d75b61 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,12 +49,14 @@ void requestCaptureAndWait(const CaptureRequest& req) { Flameshot* flameshot = Flameshot::instance(); flameshot->requestCapture(req); - QObject::connect(flameshot, &Flameshot::captureTaken, [&](QPixmap) { - // Only useful on MacOS because each instance hosts its own widgets +#if defined(Q_OS_MACOS) + // Only useful on MacOS because each instance hosts its own widgets + QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) { if (!FlameshotDaemon::isThisInstanceHostingWidgets()) { qApp->exit(0); } }); +#endif QObject::connect(flameshot, &Flameshot::captureFailed, []() { AbstractLogger::info() << "Screenshot aborted."; qApp->exit(1);