How to completely kill a QThread
Hi,
I have a GUI application and I am using QThread to run some processing in the background. The GUI application communicates with the Qthread through signals. I need to completely kill the Qthread and free up its memory once the background processing is over. I thought that once I call the Qthread::exit(0) inside the Qthread it would get killed. But even after this it continues to respond to the Signals sent by the GUI application. This means that it does not get killed and is still consuming the memory.
Somebody please help. I am creating the thread as follows, Location_Updates is inheriting from Qthread
Code:
Location_Updates *updates;
updates = new Location_Updates(this);
updates->start();
Re: How to completely kill a QThread
exit works when you are using event loop!
if your run method doesn't invoke exec() (event loop) exit will have no effect.
Apparently you have sub-classed QThread and you shouldn't do it.
Read this http://labs.qt.nokia.com/2010/06/17/...oing-it-wrong/
Re: How to completely kill a QThread
i am calling exec() inside the run() method of thread. Should the thread cease to exist once exit is called? I try to delete it using deleteLater() but it says thread panicked.
Re: How to completely kill a QThread
Don't confuse QThread object and a thread it represents. Those are two totally different entities. The thread ceases to exist when QThread::run() function returns, the only thing that remains is the QThread object which is a similar object to QTimer, QObject or QComboBox governed by exactly the same rules.
Re: How to completely kill a QThread
So, what do I have to do to completely free the memory consumed by the Thread and the objects. When I try to use deleteLater() slot, the app crashes with message as - Thread panicked. I need some way to make the thread completely cease to exist.
Re: How to completely kill a QThread
Stop the thread and when it signals that it has finished(), destroy the QThread object.