#include #include #include #include struct Guard { Guard() {} ~Guard() { std::cout << "I enter here multiple times" << std::endl; QtConcurrent::run([]() { std::cout << "But here once, or never" << std::endl; }); } }; Guard guard() { return Guard{}; } int main(int argc, char** argv) { QApplication app(argc, argv); QFuture future = QtConcurrent::run(guard); auto* watcher = new QFutureWatcher(); { auto g = guard(); } QObject::connect(watcher, &QFutureWatcher::finished, &app, [future]() { auto guard = future.result(); }); watcher->setFuture(future); app.exec(); }