QThread实例代表一个线程,我们可以重新实现QThread::run(),要新建一个线程,我们应该先继承QThread并重新实现run()函数。
需要注意的是:
1.必须在创建QThread对象之前创建 QApplication (或QCoreApplication)对象。
2. QCoreApplication::exec() 必须只能从主线程调用,不能从QThread线程调用。
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread(QObject *parent = NULL);
~MyThread();
protected:
voidrun();
};
void MyThread::run()
{