I have a Class DeviceManager:
{
this->moveToThread(thread);
connect(thread, SIGNAL(started()), this, SLOT(autoDetect()));
thread->start();
}
void autoDetect()
{
...
emit addDevice();
...
}
DeviceManager(QObject *parent) :
QObject(parent)
{
thread = new QThread();
this->moveToThread(thread);
connect(thread, SIGNAL(started()), this, SLOT(autoDetect()));
thread->start();
}
void autoDetect()
{
...
emit addDevice();
...
}
To copy to clipboard, switch view to plain text mode
Class MainForm:
{
this->manager = new DeviceManager();
connect(manager, SIGNAL(addDevice()), this, SLOT(slot()));
}
void refresh()
{
this->manager->deleteLater();
this->manager = new DeviceManager();
connect(manager, SIGNAL(addDevice()), this, SLOT(slot()));
}
MainForm(QObject *parent) :
QObject(parent)
{
this->manager = new DeviceManager();
connect(manager, SIGNAL(addDevice()), this, SLOT(slot()));
}
void refresh()
{
this->manager->deleteLater();
this->manager = new DeviceManager();
connect(manager, SIGNAL(addDevice()), this, SLOT(slot()));
}
To copy to clipboard, switch view to plain text mode
I have a problem is manager don't disconnect. When mainForm call refresh many time (eg: 3 times), then when slot() is executed 4 times.
I think that the older manager's connect is disconnect or object can't deleted.
I tried delete thread but I got message:
QThread: Destroyed while thread is still running
How to stop thread while thread is still running?
Bookmarks