[Qt-interest] QThread::run() running in wrong thread
Thiago Macieira
thiago at kde.org
Sun May 23 15:55:22 CEST 2010
Em Domingo 23. Maio 2010, às 14.32.31, Ove Fagerheim escreveu:
> Can someone here help out a newbie?
> I've created a new thread, but it seems like the thread's code is run
> from the main thread, as shown by the fprintf statement. Where did I go
> wrong?
>
> class MyThread : public QThread
> {
> .
> .
> void run() { fprintf(stderr, "MyThread is %p\n", thread(); }
> .
> .
> };
The fprintf statement is wrong, not the thread in which run() runs.
QObject::thread() returns the thread the QObject has affinity to. Unless you
move the object, it has affinity to the thread it was created in.
I think you were looking for QThread::currentThread().
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100523/3b3f237f/attachment.bin
More information about the Qt-interest-old
mailing list