[Qt-interest] QThread Question
Bradley T. Hughes
bradley.hughes at nokia.com
Thu Aug 6 13:51:44 CEST 2009
Donal O'Connor wrote:
> Thanks Sean for your good explanations.
>
> William,
> I've indeed done this but had problems finding GUI thread ID but got this
> via: QApplication::instance()->thread()->currentThreadId();
Remember that QThread::currentThreadId() is a static function, always
returning the id for the *calling* thread.
If you want to check if 2 objects have the same thread affinity, it's enough
to compare the QThread pointers returned by QObject::thread(). For example:
if (object->thread() != qApp->thread())
qFatal("PANIC");
> Both the slot thead ID and the GUI thread ID match so that's enough.
>
> No wonder this application was running slow and things blocking eachother.
>
> Thanks to everyone for their help, I've learned a lot.
>
>
> Regards,
> Donal
>
> On Thu, Aug 6, 2009 at 12:30 PM, william.crocker at analog.com <
> william.crocker at analog.com> wrote:
>
>>
>> Donal O'Connor wrote:
>>> Hi,
>>>
>>> I've got code here written by somebody else that seems to make use of
>>> several threads but I'm quite worried that the processing is not done in
>>> a different thread like intended.
>>>
>> When in doubt, print the id of the current thread from
>> the context of code in question and compare this with the
>> id of the main thread.
>>
>> QThread *QThread::currentThread () [static]
>> Returns a pointer to a QThread which represents
>> the currently executing thread.
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
--
Bradley T. Hughes (Nokia-D-Qt/Oslo), bradley.hughes at nokia.com
Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway
More information about the Qt-interest-old
mailing list