I am trying upon some simple applications. I would like to know how to launch a new form by clicking a button from main window. Please explain this to me with a simple example.
Asked
Active
Viewed 2.4k times
1 Answers
7
QT already comes with a simple example on how to create and show different types of windows and dialogs. Take a look here: Window Flags Example
Also if you already have a main widow in your application, you can take a look how it's shown (main
function in your main.cpp) for your project and use the same technique:
MainWindowTest *testWindow = new MainWindowTest();
testWindow->show();
If you need to show a modal dialog, use your dialog's exec()
method:
Dialog *dialog = new Dialog();
dialog->exec();
hope this helps, regards

serge_gubenko
- 20,186
- 2
- 61
- 64
-
5no what am i askin is when i create a new project say myqt it'll generate 1) a from "mainwindow.ui" 2) a header "mainwindow.h" 3) two source files "main.cpp" and "mainwindow.cpp".. now i need to add a from say "myform.ui" how do i launch or make the form visible when i press a button from "mainwindow" – Ashok Jeev Feb 22 '11 at 04:23
-
create your form MyForm *form = new MyForm(); then call form->show(); and will get shown. – serge_gubenko Feb 22 '11 at 12:27
-
thanks dude!! but im completely new to qt so where the code must be given? in the main.cpp?? what are the extra files i need to create?? like Myform.ui, Myform.h and Myform.cpp.. please tell me more clearly.. – Ashok Jeev Feb 23 '11 at 04:41
-
21. create a QT project, if you're using QT creator it would automatically add a main window to the project; 2. place a QPushButton on the main window; 4. add an "onclick" slot to the button; 4. create another window (if you're using QT creator see "new" menu option); 5. in the "onclick" instantiate the second window and show it. – serge_gubenko Feb 23 '11 at 12:29