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

Ove Fagerheim ove.fagerheim at nax.no
Sun May 23 17:08:30 CEST 2010


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();
}

best regards
Ove


-------------- next part --------------
An embedded message was scrubbed...
From: Thiago Macieira <thiago at kde.org>
Subject: Re: [Qt-interest] QThread::run() running in wrong thread
Date: Sun, 23 May 2010 15:55:22 +0200
Size: 7093
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100523/ce7f9d84/attachment.mht 


More information about the Qt-interest-old mailing list