#include <QtCore/QCoreApplication>
#include <QTimer>
#include <QThread>
#include <iostream>
using namespace std;
{
protected:
virtual void run()
{
QTimer::singleShot(1000,
this,
SLOT(quit
()));
exec();
//QThread::run();
}
};
{
Q_OBJECT
public slots:
void run()
{
t = new MyThread;
connect(t, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
t->start();
}
private slots:
void handleThreadFinished()
{
cout << "the thread is finished, isRunning = " << (t->isRunning() ? "true" : "false") << endl;
t->deleteLater();
}
private:
MyThread *t;
};
int main(int argc, char *argv[])
{
Test test;
QTimer::singleShot(0,
&test,
SLOT(run
()));
return a.exec();
}
#include "main.moc"
#include <QtCore/QCoreApplication>
#include <QTimer>
#include <QThread>
#include <iostream>
using namespace std;
class MyThread: public QThread
{
protected:
virtual void run()
{
QTimer::singleShot(1000, this, SLOT(quit()));
exec();
//QThread::run();
}
};
class Test: public QObject
{
Q_OBJECT
public slots:
void run()
{
t = new MyThread;
connect(t, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
t->start();
}
private slots:
void handleThreadFinished()
{
cout << "the thread is finished, isRunning = " << (t->isRunning() ? "true" : "false") << endl;
t->deleteLater();
}
private:
MyThread *t;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Test test;
QTimer::singleShot(0, &test, SLOT(run()));
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks