Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to call form2.ui from form1.ui?
QtWS25 Last Chance

How to call form2.ui from form1.ui?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.7k Views
  • 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 Offline
    O Offline
    okiewardoyo
    wrote on last edited by
    #1

    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
    0
    • X Offline
      X Offline
      Xander84
      wrote on last edited by
      #2

      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
      0
      • O Offline
        O Offline
        okiewardoyo
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          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
          0
          • O Offline
            O Offline
            okiewardoyo
            wrote on last edited by
            #5

            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
            0
            • X Offline
              X Offline
              Xander84
              wrote on last edited by
              #6

              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
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved