Results 1 to 4 of 4

Thread: Passing a child from a QThread to a QMainWindow

  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    2

    Default Passing a child from a QThread to a QMainWindow

    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
    Qt Code:
    1. myObject->moveToThread(QApplication::instance()->thread());
    To copy to clipboard, switch view to plain text mode 
    But nothings happens, i also tried to force with the setParent() method but none of these worked.

    How can i fix it?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing a child from a QThread to a QMainWindow

    Create the object without the parent, then move it to a proper thread and then set a parent on it if you want to.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    2

    Default Re: Passing a child from a QThread to a QMainWindow

    Quote Originally Posted by wysota View Post
    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?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Passing a child from a QThread to a QMainWindow

    don't pass it into an object's ctor.
    Qt Code:
    1. ...
    2. MyObject *mo = new MyObject();
    3. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. QMainWindow as a child of QMainWindow
    By Elder Orb in forum Qt Programming
    Replies: 8
    Last Post: 12th February 2011, 22:31
  2. Replies: 3
    Last Post: 12th August 2008, 20:14
  3. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 08:16
  4. Replies: 2
    Last Post: 27th March 2007, 13:09
  5. Showing QMainWindow without showing a child QWidget
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 10:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.