|
1Qter豆
// .h头文件class A : public QObject{ Q_OBJECT
public: A(); ~A();public: QThread *m_thread;
public slots: void run();};// .cpp文件A::A():QObject(){ m_thread = new QThread; this->moveToThread(m_thread); connect(m_thread, SIGNAL(finished()), this, SLOT(deleteLater())); m_thread->start();}
void A::run(){ qDebug()<<"run thread:"<<QThread::currentThread()<<this; m_thread->quit(); m_thread->wait();}
int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); qDebug()<<"main thread:"<<QThread::currentThread(); A m; QTimer::singleShot(200, &m, &A::run); return a.exec();}上述代码在程序运行过程中会报错,各位大佬知道是啥原因不?
|
|