Results 1 to 5 of 5

Thread: Stopping a QThread

  1. #1
    Join Date
    Apr 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Stopping a QThread

    Hi, while maing a project I've encountered a situation wherein i want to calculate something (lots of calculations) until it is A: done, or B: the user presses a button.
    In case B, the calculation need to start all over again with new parameters

    (info: calculating the solvability of a puzzle like this: http://www.quirkle.com/puzzle/)

    So everytime a user presses the button I create a new QThread that wil calculate some things, but what I want, is that when a user presses the button, all active threads stops en are deleted, so there is always only one thread busy...

    Is it possible to properly disable en delete a qthread??

    thans for considering.

  2. #2
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Stopping a QThread

    Quote Originally Posted by Gurdt View Post
    Hi, while maing a project I've encountered a situation wherein i want to calculate something (lots of calculations) until it is A: done, or B: the user presses a button.
    In case B, the calculation need to start all over again with new parameters

    (info: calculating the solvability of a puzzle like this: http://www.quirkle.com/puzzle/)

    So everytime a user presses the button I create a new QThread that wil calculate some things, but what I want, is that when a user presses the button, all active threads stops en are deleted, so there is always only one thread busy...

    Is it possible to properly disable en delete a qthread??

    thans for considering.
    You can terminate the thread by using terminate() and join(), but better to use your own parameter to control termination of the thread; And you might not want to create and delete threads every time if they are basically same, just check the status of the thread and restart it.

  3. #3
    Join Date
    Apr 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Stopping a QThread

    The problem is that with terminate and join (in qt "wait' this is) it seems that I still need to wait on the threads until they finish, but I wan't to stop the current calculations en start over with new data, in the same or in another thread, it doesn't really matter

  4. #4
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Stopping a QThread

    Quote Originally Posted by Gurdt View Post
    The problem is that with terminate and join (in qt "wait' this is) it seems that I still need to wait on the threads until they finish, but I wan't to stop the current calculations en start over with new data, in the same or in another thread, it doesn't really matter
    check isRunning() method

  5. #5
    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: Stopping a QThread

    Are you sure you need the other thread?

    Have you tried the suggestions from the QQ article about keeping your GUI responsive?
    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. QThread and QTcpSocket
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2008, 13:06
  2. Spawn a QThread in another QThread
    By david.corinex in forum Qt Programming
    Replies: 2
    Last Post: 19th December 2007, 12:54
  3. Using QUdpSocket within a QThread
    By db in forum Newbie
    Replies: 18
    Last Post: 30th October 2007, 23:59
  4. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51

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.