Hello
How can I create more than one forms ( .ui ) by using a qt creator.
If you press the button in first form ===> I watch the second form.
Thank you
Hello
How can I create more than one forms ( .ui ) by using a qt creator.
If you press the button in first form ===> I watch the second form.
Thank you
Qt Creator is a text editor. You may input the code using any text editor you want.
You are able to start a new project with Qt Creator based on QMainWindow or QDialog right ? (Use File - New - Qt QUI Application).
In your project, do again File - New - Qt - Designer Form Class. This way you create the files (ui, cpp, header) for your second form.
Put a button on your first form, and in the 'clicked()' slot you just put the following code :
Qt Code:
CMySecondForm *pSecondForm = new CMySecondForm ( this ); pSecondForm ->exec(); delete pSecondForm ;To copy to clipboard, switch view to plain text mode
This creates an instance of your second form, and shows it. Of course you have to include the header of your second form in the cpp file of your first form.
Best regards,
Marc
@Marc, nice tutorial, only one small correction: you should not delete the second dialog pointer, because you gave it a parent (the "this" pointer - which is a pointer to the mainwindow in this case)
You have been given all the code you need! What more do you want!? Do you want me to paste the code from the FAQ into my post? Will that make any difference to you? If you are not able to create a widget with Creator then don't use it and code your widgets manually. If you are able to create a widget with Creator, then just combine it with code from the FAQ. If you don't know how to create a widget then maybe you should focus on that first instead of trying to create two widgets...
Hi Zlatomir,
Now I have a question...
If I don't want the second form to live any longer then the time needed to show the dialog (e.g. for a modal dialog), what do I do then ? Just create the QDialog without a parent ? So...
I assumed that the parent was also needed for the operating system to know what windows are related (e.g. if you minimize the main window that all child windows are minimized also). But maybe my assumption is wrong.Qt Code:
CMySecondForm *pSecondForm = new CMySecondForm(); pSecondForm->exec(); delete pSecondForm;To copy to clipboard, switch view to plain text mode
There is no method of QWidget to make it delete one of its children. Maybe I could do setParent(0) of my pSecondForm and then do my own delete ?
Best regards,
Marc
In case of a modal dialog, you can allocate on stack
and if you have created one with default buttons do some of this:
Qt Code:
void MainWindow::slot_connected_with_button_s_clicked (){ secondModalDialog dlg(this); if (dlg.exec() == Accepted) { //do the work if user clicked "Ok" on your modal dialog; } }To copy to clipboard, switch view to plain text mode
Guys, look into the FAQ please
I have two forms. How to open a second form after a button is clicked in the first one?
Sorry...
Zlatomir, I just should'nt have put the delete in my code because the OP probably didn't want the second form to be modal. Your remark got me side-tracked about what would happen if the parent would try and delete a child that I already deleted myself. But that's no problem I guess. Probably the destructor of the child notifies the parent that it is being deleted and it gets removed form the list of children.
@NewLedgend : so just don't do the delete.... and read the FAQ ...
Best regards,
Marc
Bookmarks