65,189
社区成员




#ifndef TESTOBJ_H
#define TESTOBJ_H
#include <QObject>
class TestObj : public QObject
{
Q_OBJECT
public:
explicit TestObj(QObject *parent = nullptr);
~TestObj();
};
#endif // TESTOBJ_H
#include "testobj.h"
#include <QDebug>
TestObj::TestObj(QObject *parent) : QObject(parent)
{
qDebug()<<"构造函数";
}
TestObj::~TestObj()
{
qDebug()<<"析构函数";
}
run函数:
void QMyThread::run()
{
QTimer timer;//定时器,做超时检测
QEventLoop loop;
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
m_pObj = new TestObj;
timer.start(1000);
loop.exec();
m_pObj->deleteLater();
}
输出:
Starting D:\FTP\build-untitled-mingw32-Debug\debug\untitled.exe...
构造函数
析构函数
D:/FTP/build-untitled-mingw32-Debug/debug/untitled.exe exited with code 0