سؤال

I'm using Qt 4.7.0 (32 bit) on Windows 7 Ultimate (32 bit) machine. I've been using Qt probably from version 4.0 or 4.2 and I've used almost all 4.x.y releases.

Recently, with Qt 4.7 I've faced trouble.

I've written a multithreaded application in some older version of Qt. I've forgotten the version but probably the last version where I compiled and ran properly is 4.5.x or 4.6.x. The threaded part doesn't seem to be working correctly in 4.7, or I misunderstood something. Here is the problem:

The main thread starts thinker thread. Following is the run() function of thinker thread:

void ThinkerThread::run()
{
    _threads_running = NSUBTHINKERS;

    // ...
    _sub_thinker[0].start();

    // ...    
    _sub_thinker[1].start();

    exec();
}

The _sub_thinker's finished() signal is connected with ThinkerThread::subThinkerFinished() slot for all _sub_thinkers. When all _sub_thinkers finish, ThinkerThread::subThinkerFinished() calls quit().

There is another place where quit() is called:

void ThinkerThread::tryKill()
{
    for (int i = 0; i < NSUBTHINKERS; i++)
        _sub_thinker[i].tryKill();
    quit();
}

From main thread, the execution is like as follows:

  • thinker.tryKill() [Note: On very fist run, thinker wasn't running.]
  • thinker.start()

thinker's finished() signal is connected with autoMove().

For all previous versions of Qt, autoMove() was called after thinker::quit() is called from ThinkerThread::subThinkerFinished(). In 4.7 I'm seeing that autoMove() is called after the very first call of thinker.tryKill(), even though the thread wasn't running.

Any idea?

Of course I can check inside ThinkerThread::tryKill() if thinker is running or not. But I'd like to know why is this happening.

Thanks.

هل كانت مفيدة؟

المحلول

I've found that QThread::finished() is emitted every time QThread::quit() is called irrespective of the state of QThread (i.e., running/not running). It didn't the case for previous versions of Qt.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top