Created
March 23, 2018 14:17
-
-
Save suy/7515df1ffb278559ba1fd7dacbdf2d24 to your computer and use it in GitHub Desktop.
QThreadPool lingers till the end of the app, for good or bad
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
#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