Results 1 to 6 of 6

Thread: Qthreads

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    29
    Thanked 3 Times in 2 Posts

    Default Re: Qthreads

    It might not apply to your job, but...

    if you need to break off your job (stopping the thread in the middle of it's work) you can use a 'bool keepRunning' member variable in the threaded function.

    run(){
    keepRunning = true;
    do{
    //whatever - some short job
    }while(someCondition&&keepRunning);

    Then sub-class quit to look like

    void AutomationThread::quit()
    {
    keepRunning = false;
    QThread::quit();
    }
    Then you can stop the thread with
    myThread->quit();
    myThread->wait();//this will wait a maximum of one loop iteration.

    Not always applicable, but I use that method all the time - my threads can run for hours (monitoring things, waiting)

    by the way, a long sleep in my thread then looks like
    for(int i=0; i<someLargeWait&&keepRunning; ++i){
    msleep(100);
    }
    which can also be broken off quickly.

    K

  2. The following user says thank you to TheKedge for this useful post:

    Sheetal (29th March 2007)

Similar Threads

  1. QTcpSockets and QThreads
    By TheRonin in forum Newbie
    Replies: 3
    Last Post: 21st June 2006, 09:41

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
  •  
Qt is a trademark of The Qt Company.