P
P
Pavel K2016-02-07 16:42:28
Qt
Pavel K, 2016-02-07 16:42:28

QThread why is the class destructor not called?

Greetings!
Created a new FindTargets class inherited from QObject
with a stream running in the AppCore class in the constructor:

ft = new FindTargets(0);
thread = new QThread(0);
connect(thread, SIGNAL(started()), ft, SLOT(process()));
connect(ft, SIGNAL(finished()), thread, SLOT(quit()));
connect(ft, SIGNAL(finished()), ft, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
ft->moveToThread(thread);
thread->start();

in destructor:
AppCore::~AppCore()
{
   qDebug()<<"AppCore::~AppCore";
   ft->stop();
}

In the FindTargets class, there is an infinite while loop that, as soon as it stops, signals finished() and the stop() function that stops it directly.
To terminate the program, I created a connection:
QObject::connect(&app, SIGNAL(aboutToQuit()), appCore, SLOT(deleteLater()));
BUT the FindTargets::~FindTargets() destructor is not called
Output:
AppCore::~AppCore //-- the destructor of the main class
FindTargets::stop has worked //-- stop() has worked
on this the program ends (it actually ends, there are no hanging processes! )
If I call ft->stop() elsewhere, the FindTargets::~FindTargets destructor will be called.
Can you please tell me why the FindTargets::~FindTargets destructor is not called??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel K, 2016-02-09
@PavelK

In general, I found a solution.
The problem was that the thread and the working class were created in a class that itself is killed when the last program window is closed, and since everything was connected via signal slots, they stopped being called. It was only necessary to leave the main class alive after closing the window, then everything returned to normal, well, I just added that the main class would be killed when the thread finished working.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question