Results 1 to 5 of 5

Thread: Multiple start() on same QThread Object

  1. #1
    Join Date
    Mar 2007
    Posts
    29
    Thanks
    2

    Angry Multiple start() on same QThread Object

    Hi all,
    can I run multiple start() method on same QThread object ?

    Simple example follows:


    Qt Code:
    1. int main(int argc, char *argv[]){
    2. QCoreApplication app(argc,argv);
    3. threadHandler *TH=new threadHandler();
    4. TH.start()
    5. TH.start()
    6.  
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    This code executes the two run() methods as two serial executions.
    Is this correct? Do you have experience in this?

    Thanks,
    Michele
    Last edited by wysota; 13th April 2007 at 16:12.

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Multiple start() on same QThread Object

    No, only the first call will be effective.
    If you call start() a second time while the thread is running, it will do nothing !

    http://doc.trolltech.com/4.2/qthread.html#start

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Multiple start() on same QThread Object

    You can use the same class, but two objects, to get two threads. Myabe this is what you want.

  4. #4
    Join Date
    Jan 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiple start() on same QThread Object

    Quote Originally Posted by guilugi View Post
    No, only the first call will be effective.
    If you call start() a second time while the thread is running, it will do nothing !

    http://doc.trolltech.com/4.2/qthread.html#start
    Am I correct if I suppose this means that start() can be called several times IF the run() method has returned between the calls?

  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: Multiple start() on same QThread Object

    Yes, you can start the thread again when it has already finished.
    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. Object and multiple inheritance for interfaces
    By brcain in forum Qt Programming
    Replies: 8
    Last Post: 29th June 2021, 15:29
  2. Replies: 2
    Last Post: 27th March 2007, 12:09
  3. QThread : run() Vs start()
    By cs_raja in forum Qt Programming
    Replies: 4
    Last Post: 21st November 2006, 10:36
  4. Replies: 4
    Last Post: 10th May 2006, 22:37
  5. Multiple inheritance & Qt
    By dublet in forum Qt Programming
    Replies: 11
    Last Post: 8th March 2006, 08:12

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.