Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.3.0, 6.3.1
-
None
-
Operating System: Arch Linux
KDE Plasma Version: 5.25.0
KDE Frameworks Version: 5.95.0
Kernel Version: 5.17.9-258-tkg-pds (64-bit)
Graphics Platform: X11
Processors: 8 × Intel® Core™ i7-9700K CPU @ 3.60GHz
Memory: 31.3 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 2060/PCIe/SSE2
Qt6-Version: 6.3.1-1Operating System: Arch Linux KDE Plasma Version: 5.25.0 KDE Frameworks Version: 5.95.0 Kernel Version: 5.17.9-258-tkg-pds (64-bit) Graphics Platform: X11 Processors: 8 × Intel® Core™ i7-9700K CPU @ 3.60GHz Memory: 31.3 GiB of RAM Graphics Processor: NVIDIA GeForce RTX 2060/PCIe/SSE2 Qt6-Version: 6.3.1-1
Description
When using the "Thread-Safe Event" paradigm:
class QEventExecutor : public QEvent { using callback_t = std::function<void()>; private: callback_t m_func; public: QEventExecutor(callback_t &&func) : QEvent(QEvent::None), m_func(std::move(func)) {} ~QEventExecutor() override { m_func(); } }; // Somewhere else in a different thread QApplication::postEvent(/*receiver*/, new QEventExecutor([] {/*...*/}));
And accessing the WindowFlags, the application will not exit correctly when the last Window is closed.
This behavior does not occur in Qt 6-2.6.4 downwards, Qt5 is also not affected.
Here's a full reproduction example (can also be found as an attachment):
#include <QApplication> #include <QMainWindow> #include <functional> #include <future> #include <thread> class QEventExecutor : public QEvent { using callback_t = std::function<void()>; private: callback_t m_func; public: QEventExecutor(callback_t &&func) : QEvent(QEvent::None), m_func(std::move(func)) {} ~QEventExecutor() override { m_func(); } }; int main(int argc, char **argv) { auto QApp = QApplication(argc, argv); auto *main = new QMainWindow(); main->setWindowTitle("Bug Report"); main->setFixedSize(500, 600); // auto fut_ptr = std::make_shared<std::future<void>>(); // *fut_ptr = std::async(std::launch::async, [fut_ptr, &main] { // std::this_thread::sleep_for(std::chrono::seconds(2)); // QApplication::postEvent(main, new event_callback([&main] { // main->setWindowTitle("Works, application exits!"); // main->close(); // })); // }); auto fut_ptr = std::make_shared<std::future<void>>(); *fut_ptr = std::async(std::launch::async, [fut_ptr, &main] { std::this_thread::sleep_for(std::chrono::seconds(2)); QApplication::postEvent(main, new QEventExecutor([&main] { //? Doesn't work, window closes, application doesn't exit main->setWindowFlag(Qt::FramelessWindowHint, true); main->close(); })); }); main->show(); QApplication::exec(); }