Results 1 to 2 of 2

Thread: QThread isRunning() clarification

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Location
    Hyderabad, India
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QThread isRunning() clarification

    Please clarify my doubt regarding isRunning() method as written in Qt 'Blocking Fortune Client Example'.

    Here requestNewFortune() method is executing in the context of Main thread and 'this' object affinity is also Main thread then isRunning() should check whether main thread is running or not. But it looks like this is not the case.

    isRunning() documentation says:

    Returns true if the thread is running; otherwise returns false.

    My doubt is which thread isRunning() method checking here - main thread or the thread which still not exist as run() method not called. or its checkin whether run() method ever called on this object before or not. In the later case documentation is not right.


    Qt Code:
    1. void FortuneThread::requestNewFortune(const QString &hostName, quint16 port)
    2. {
    3. QMutexLocker locker(&mutex);
    4. this->hostName = hostName;
    5. this->port = port;
    6. if (!isRunning())
    7. start();
    8. else
    9. cond.wakeOne();
    10. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QThread isRunning() clarification

    QThread::isRunning() operates on the thread controlled by 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.


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

    raj_iv (20th January 2013)

Similar Threads

  1. QThread::isRunning returns true after emitting finished signal
    By mentalmushroom in forum Qt Programming
    Replies: 10
    Last Post: 1st August 2012, 06:48
  2. MoveToThread clarification
    By Thuan Seah Tan in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2012, 10:32
  3. QThread clarification
    By janorcutt in forum Qt Programming
    Replies: 5
    Last Post: 6th January 2011, 09:11
  4. Clarification about dataChanged
    By airbites in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 16:02
  5. how isRunning() finds thread is running?
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 13th June 2006, 08:03

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.