I have a class:
class centralDataPool : public QObject
{
Q_OBJECT
public:
centralDataPool(QObject * parent = 0);
~centralDataPool();
commMonitor commOverWatch;
private:
QThread monitorThread;
int totalNum;
signals:
void createMonitor(int);
};
In its constructor I did:
centralDataPool::centralDataPool(QObject* parent) : QObject(parent),totalNum(0)
{
connect(this, SIGNAL(createMonitor(int)), &commOverWatch, SLOT(createMonitor(int)));
commOverWatch.moveToThread(&monitorThread);
monitorThread.start();
}
when I called the destructor of this class I get the error message:
qthread destroyed while thread is still running
But when I tried to terminate the monitorThread in the destructor of class centralDataPool,
centralDataPool::~centralDataPool()
{
monitorThread.terminate();
}
I get memory leakage.
What is the correct way to terminate a thread during the destruction of its owner object ?