Results 1 to 4 of 4

Thread: about qtabwidget and parenting

  1. #1
    Join Date
    Mar 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default about qtabwidget and parenting

    Hi, im developing a small desktop application from my ubuntu qtCreator.. and ive having an error im not able to solve.

    this is the relevant code:
    Qt Code:
    1. QWidget *nw = new QWidget();
    2. std::string final = "some text here";
    3. QLabel *lblText = new QLabel(QString::fromStdString(final));
    4. QVBoxLayout *mainLayout = new QVBoxLayout;
    5. mainLayout->addWidget(lblText);
    6. nw->setLayout(mainLayout);
    7. ui->tabNews->addTab(nw, tr("Confirmation"));
    To copy to clipboard, switch view to plain text mode 
    the error is:
    QObject::setParent: Cannot set parent, new parent is in a different thread

    ive previosly done a custom widget on a ui file and tried to load it on that tab with the same result and tried to create the widget on the same class where this window is created... with the same result.

    Can anyone see the problem with this little code? :S im not explicitelly using threads on the view layer...

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: about qtabwidget and parenting

    That code doesn't look like it would generate that warning.

    But just in case, make sure you are not executing that code in a thread other than the one executing QApplication::exec()

    Cheers,
    _

  3. #3
    Join Date
    Mar 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: about qtabwidget and parenting

    thats why i though.
    Not a single thread is involved on the entire process.
    The flux is as follows:
    main.cpp:
    Qt Code:
    1. Core *core = new Core(os);
    2. core->iniciar();
    3. return a.exec();
    To copy to clipboard, switch view to plain text mode 

    core.cpp:
    Qt Code:
    1. bi = new Interface();
    2. gif = new GUIInterfaceFactory();
    3. bi->setGUIInterface(gif);
    To copy to clipboard, switch view to plain text mode 

    Interface.cpp:
    Qt Code:
    1. gi = gif->getGUIInterface(this);
    2. gi->getLoggedIn();
    To copy to clipboard, switch view to plain text mode 

    GUIInterface.cpp:
    Qt Code:
    1. cw = new ChatWindow();
    2. cw->show();
    To copy to clipboard, switch view to plain text mode 

    and finally ChatWindow.cpp contains the code i posted on the first post. As u can see, i did not manually create a single thread on the entire process.
    If u are interested u can see most of the code ad http://sourceforge.net/p/rm-navi/code/ci/master/tree/ but is pretty big

  4. #4
    Join Date
    Mar 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: about qtabwidget and parenting

    problem & solution:
    After some hours working on it, i saw that the problem was on the call. I did a smaller project and worked on it to proof the failure.
    the problem is ive got a server with some thread, all petition received by this server is heared throught an interface on the main thread and this interface is who manages the GUI. So i think that little code call to be processed on the thread where is called and not where it was originally defined.
    As solution: just use signals.

Similar Threads

  1. Replies: 6
    Last Post: 21st August 2013, 12:53
  2. QGraphicsSvgItem changes position after parenting
    By dodgeit in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2011, 18:32
  3. QTabWidget Parenting Problem
    By mclark in forum Newbie
    Replies: 4
    Last Post: 18th January 2007, 15:20
  4. [QTabWidget] parenting (solved)
    By lauranger in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2006, 10:32
  5. Parenting QWindow...
    By roomie in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 09:06

Tags for this Thread

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.