How to call form2.ui from form1.ui?
-
How to call form2.ui from form1.ui?
I have a form1.ui as the main form project, i create a pushButton on it.
then i create another form using qt designer, let's call it form2.ui.
How to show form2.ui when the pushButton on form1.us clicked? -
Hi, the form2.ui should usually have a C++ companion class for the logic and interaction (you can call it the controller if you want), so you can include that file (form2.h) and create an object and show it like any other QWidget.
That is at least the default way I guess, if you don't have a controller class there are other ways to create an object, but lets assume you are using it like this? :)
-
so, if i created another .ui files using qt designer, should i create another .h and .cpp files too??
-
There already is a template generator for that, you just have to use the template "Qt Designer Form Class" instead of just the .ui file template "Qt Designer Form" then Qt Creator will generate the .ui file and also the .cpp and .h for you in one step :)
-
Ok, i will try it,
i just want to create a menu of "about"
then i create a .ui file from designer, yes it's .ui files. No cpp and h there , just ui files. :) -
Well as I've said you can create objects of the "ui" file, because qmake will generate a file like ui_form1.h from your form1.ui file, but that file is auto generated and will be overwritten when you recompile your app, so you can't modify that class. That is why you should use a controller class for the UI file if you want logic or whatever (like a button click slot or calculations etc).
you can open the ui_form.h files and see what qmake will generate for you, if that helps the file should be in your build folder.