Hi, this problem might sound weird, but it got me crazy as I just started using QThread. Here is a short program to test using QThread.
#include <QThread>
#include <QCoreApplication>
#include <QDebug>
int main (int argc, char** argv) {
t.start();
if (t.isRunning())
qDebug() << "thread is started";
//t.exit();
//t.quit();
t.terminate();
qDebug() << "try to stop thread";
if(!t.isRunning())
qDebug() << "thread is stopped";
return app.exec();
}
#include <QThread>
#include <QCoreApplication>
#include <QDebug>
int main (int argc, char** argv) {
QCoreApplication app(argc, argv);
QThread t;
t.start();
if (t.isRunning())
qDebug() << "thread is started";
//t.exit();
//t.quit();
t.terminate();
qDebug() << "try to stop thread";
if(!t.isRunning())
qDebug() << "thread is stopped";
return app.exec();
}
To copy to clipboard, switch view to plain text mode
I tried exit(), quit() and terminate() and waited for a long time.
The expected "thread is stopped" never ever shows up (no matter how long I waited). The thread is like running forever. Could anyone help me with this and show me how to properly stop a QThread?
Thank you.
Ves
Bookmarks