PDA

View Full Version : Passing a child from a QThread to a QMainWindow



sgtbash
3rd May 2009, 14:20
Hi guys, i have a problem. I've a QWizard which have a some instruction which take a little bit time, so i decided to create a thread just to do these operations. At the end of this thread i have a new QObject created by this QThread, and i want to pass it to the QMainWindow, the point is that this new QObject is child of QThread and i get this :

QObject: Cannot create children for a parent that is in a different thread.
I tried to move the Object like in the example of the documentation

myObject->moveToThread(QApplication::instance()->thread());
But nothings happens, i also tried to force with the setParent() method but none of these worked.

How can i fix it?

wysota
4th May 2009, 08:56
Create the object without the parent, then move it to a proper thread and then set a parent on it if you want to.

sgtbash
4th May 2009, 09:10
Create the object without the parent, then move it to a proper thread and then set a parent on it if you want to.

I'm sorry, how do I create the object without a parent?

spirit
4th May 2009, 09:30
don't pass it into an object's ctor.


...
MyObject *mo = new MyObject();
...