PDA

View Full Version : QThread isRunning() clarification



raj_iv
20th January 2013, 17:18
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.



void FortuneThread::requestNewFortune(const QString &hostName, quint16 port)
{
QMutexLocker locker(&mutex);
this->hostName = hostName;
this->port = port;
if (!isRunning())
start();
else
cond.wakeOne();
}

wysota
20th January 2013, 18:10
QThread::isRunning() operates on the thread controlled by the QThread object.