Results 1 to 5 of 5

Thread: [QThread] Function calling after thread.stop()

  1. #1
    Join Date
    Jan 2009
    Posts
    51
    Thanks
    28
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [QThread] Function calling after thread.stop()

    I'd like my thread to do something after quiting, when stop method is called.
    For example I have opened file in my thread, and I want to close it when thread is stopping.
    How to do it?

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

    Default Re: [QThread] Function calling after thread.stop()

    The best way would be to do the cleanup before QThread::run() returns. If it is not possible then you can do the cleanup in the QThread object destructor (just remember it will be ran in the context of the thread that created the object, not the thread created by the object).

  3. The following user says thank you to wysota for this useful post:

    Macok (7th February 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    51
    Thanks
    28
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [QThread] Function calling after thread.stop()

    So if I add it to destructor I must always call "delete thread" when stopping thread?

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

    Default Re: [QThread] Function calling after thread.stop()

    No, it only means the cleanup wil not be performed by the thread itself but the thread that created the QThread object. Read about thread affinity in Qt Reference Manual.

  6. The following user says thank you to wysota for this useful post:

    Macok (7th February 2009)

  7. #5
    Join Date
    Jan 2009
    Posts
    51
    Thanks
    28
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [QThread] Function calling after thread.stop()

    @Edit
    Ok, problem is solved.
    Thanks again wysota
    Last edited by Macok; 7th February 2009 at 19:03.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 15:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 13:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 18:33
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 13:52

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.