Last active
January 26, 2018 09:32
-
-
Save Razzo78/fd60909de1ca0cedd7e61173918958ca to your computer and use it in GitHub Desktop.
QT - Execute a function from a task thread in the main thread context.
This is useful to update UI, without cross thread errors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ThreadToolUI::PostToMainThread(const std::function<void()> & fun) | |
{ | |
QObject signalSource; | |
QObject::connect(&signalSource, &QObject::destroyed, qApp, [=](QObject*){ | |
fun(); | |
}); | |
} | |
Task::run<void>([=]() { | |
qDebug() << "Current therad is task thread"; | |
ThreadToolUI::PostToMainThread([=]() { | |
qDebug() << "Current therad is main thread"; | |
}); | |
}).start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment