Results 1 to 6 of 6

Thread: How to completely kill a QThread

  1. #1
    Join Date
    Oct 2011
    Posts
    14
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default 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
    Qt Code:
    1. Location_Updates *updates;
    2. updates = new Location_Updates(this);
    3. updates->start();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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/

  3. #3
    Join Date
    Oct 2011
    Posts
    14
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2011
    Posts
    14
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default 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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to completely kill a QThread

    Stop the thread and when it signals that it has finished(), destroy the QThread object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 8th December 2011, 09:04
  2. Replies: 1
    Last Post: 19th December 2010, 20:08
  3. GUI completely nonfunctional in Release configuration.
    By alpinista in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2009, 09:43
  4. Completely lost!!!
    By Zuks in forum Newbie
    Replies: 4
    Last Post: 2nd December 2009, 10:58
  5. How to destroy a UdpSocket completely
    By ms20020048 in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2006, 20:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.