PDA

View Full Version : about qtabwidget and parenting



xeyos
26th July 2014, 20:50
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:

QWidget *nw = new QWidget();
std::string final = "some text here";
QLabel *lblText = new QLabel(QString::fromStdString(final));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(lblText);
nw->setLayout(mainLayout);
ui->tabNews->addTab(nw, tr("Confirmation"));
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...

anda_skoa
27th July 2014, 10:36
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,
_

xeyos
27th July 2014, 11:27
thats why i though.
Not a single thread is involved on the entire process.
The flux is as follows:
main.cpp:


Core *core = new Core(os);
core->iniciar();
return a.exec();

core.cpp:


bi = new Interface();
gif = new GUIInterfaceFactory();
bi->setGUIInterface(gif);

Interface.cpp:


gi = gif->getGUIInterface(this);
gi->getLoggedIn();


GUIInterface.cpp:


cw = new ChatWindow();
cw->show();

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

xeyos
28th July 2014, 16:17
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.