PDA

View Full Version : How to show a window widget...



agent007se
20th July 2006, 06:33
... from a QMainWindow ? (but not in main.cpp)

in CLinkGUI.cpp :


void CLinkGUI::tests()
{
ui_sofImpl test;
test.show();
}


When I do this :
in main.cpp :


int main(int argc, char **argv)
{
QApplication app(argc, argv);
ui_murefImpl window;
window.show();

ui_sofImpl test;
test.show();

return app.exec();
}

it works but that is not what I want...

my not modified main.cpp :


int main(int argc, char **argv)
{
QApplication app(argc, argv);
ui_murefImpl window;
window.show();

return app.exec();
}



The first code (in CLinkGUI.cpp) shows me my widget but close it imediately...

Thanks :D !

Please delete this topic -> I found the solution : Read the FAQ !

munna
20th July 2006, 06:48
The first code (in CLinkGUI.cpp) shows me my widget but close it imediately...

Because the widget is created in the function tests() and destroyed once out of the function.

It should rather be



void CLinkGUI::tests()
{
ui_sofImpl *test = new ui_sofImpl;
test->show();
}


Make sure you set the widget attribute Qt::WA_DeleteOnClose so that the widget is deleted automatically when it is closed.

agent007se
20th July 2006, 06:49
Because the widget is created in the function tests() and destroyed once out of the function.

It should rather be



void CLinkGUI::tests()
{
ui_sofImpl *test = new ui_sofImpl;
test->show();
}


Make sure you set the widget attribute Qt::WA_DeleteOnClose so that the widget is deleted automatically when it is closed.

I just added static before declaration of the variable :


static ui_sofImpl test;

wysota
20th July 2006, 10:42
I just added static before declaration of the variable
Take a look at the FAQ (http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_stack_creat ed_widgets) please...