[Qt-interest] [Fwd: Re: QThread::run() running in wrong thread]

Thiago Macieira thiago at kde.org
Sun May 23 18:05:32 CEST 2010


Em Domingo 23. Maio 2010, às 17.08.30, Ove Fagerheim escreveu:
> Seems like th code really is running in main thread after all. I cant
> change affinity for m_worker in workerthread, due to wrong thread
> running.
> 
> class SomeObject;
> 
> class WorkerThread : public QThread
>  {
>    .
>    create(SomeObject *pParam, QObject *pParent) {
>       m_worker = pParam;
>       m_parent = pParent;
>    }
>    .
>    void run() {
>       // Next statement still reports wrong thread
>       fprintf(stderr, "MyThread is %p\n", currentThread(); }
>       // do some work
>       // next statement failes due to code running in wrong thread
>       m_worker->moveToThread(m_parent->thread());
>    }
> 
>    QObject *m_parent;
>    SomeObject *m_worker;
>  };
> 
> int main(int argc, char *argv[])
> {
>    SomeObject * p = new SomeObject();
>    WorkerThread *thr = new WorkerThread();
>    p->moveToThread(thr);
>    thr->create(p, this);
>    thr->start();
> }

I can't help you. Your code doesn't compile (use of "this" in main).

-- 
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/797afd5c/attachment.bin 


More information about the Qt-interest-old mailing list