Skip to content

Instantly share code, notes, and snippets.

@suy
Created March 23, 2018 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suy/7515df1ffb278559ba1fd7dacbdf2d24 to your computer and use it in GitHub Desktop.
Save suy/7515df1ffb278559ba1fd7dacbdf2d24 to your computer and use it in GitHub Desktop.
QThreadPool lingers till the end of the app, for good or bad
#include <QtCore>
class TurtleRunnable : public QRunnable
{
void run() override {
for (int i = 0; i < 15; ++i) {
qDebug("Tick %i", i);
QThread::sleep(1);
}
}
};
int main(int argc, char *argv[])
{
QCoreApplication application(argc, argv);
QThreadPool::globalInstance()->start(new TurtleRunnable);
QTimer::singleShot(3000, [&application](){
qDebug("I'd like to quit now");
application.quit();
});
application.exec();
qDebug("And done");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment