Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    How to call form2.ui from form1.ui?

    General and Desktop
    2
    6
    1421
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      okiewardoyo last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • X
        Xander84 last edited by

        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? :)

        1 Reply Last reply Reply Quote 0
        • O
          okiewardoyo last edited by

          so, if i created another .ui files using qt designer, should i create another .h and .cpp files too??

          1 Reply Last reply Reply Quote 0
          • X
            Xander84 last edited by

            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 :)

            1 Reply Last reply Reply Quote 0
            • O
              okiewardoyo last edited by

              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. :)

              1 Reply Last reply Reply Quote 0
              • X
                Xander84 last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post