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. Qt new user: is it possible to switch between two .ui in same project?
QtWS25 Last Chance

Qt new user: is it possible to switch between two .ui in same project?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • B Offline
    B Offline
    Bob H AS
    wrote on last edited by
    #1

    I have two different devices with legacy code connecting to .ui's. Is it possible for me from a top-level perspective to choose between and call one .ui at a time? Can more than one .ui exist simultaneously in a project?

    -Bob

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to the forums.

      yes you can have as many UI files as you want. You can even have more main windows if you want.

      It can be very dynamic using
      https://doc.qt.io/qt-5/quiloader.html
      ( please see the sample in docs )

      However, you can also just create the 2 UI files with .h and .cpp and (GUI1, GUI2)
      and in main.cpp simply new the one you want to use. (or how you want it to work)
      You just need to have a defined interface to the legacy code they both can use to access data etc.

      The benefit of quiloader is that is designed for such use case and covers even corner cases.
      The downside is that you have to manually connect all widgets and do not have the
      direct acces via UI->.

      The benefit of just using a normal Designer widget with -h and .cpp is that you have easy access to the widgets via
      UI and all its already setup and you just need to new it, to use it.

      What the best for you is, is hard to say without more details about the difference between the GUIs and how
      they must interface with the "other" code.

      1 Reply Last reply
      2
      • B Offline
        B Offline
        Bob H AS
        wrote on last edited by
        #3

        Great, thanks mrjj.

        I really appreciate your detailed explanation here. The link to quiloader and your confirmation that yes it is possible to have as many UI files as I want - both are helpful to me.

        mrjjM 1 Reply Last reply
        1
        • B Bob H AS

          Great, thanks mrjj.

          I really appreciate your detailed explanation here. The link to quiloader and your confirmation that yes it is possible to have as many UI files as I want - both are helpful to me.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Bob-H-AS
          Hi
          You are most welcome.
          Also as a note.
          Using UI files does not exclude using code.
          The UI (with .h and .cpp) files are converted to c++ code ( look in the setupUI function)
          and you can also add elements if you wish from code.

          Using pure UI files, you get a pointer to the top widget and you can still add widgets from code if you want.

          So a mix of "static" UI file and dynamic Widgets is also possible if
          the GUI1 and GUI2 is very alike and you handle the difference runtime.

          1 Reply Last reply
          1

          • Login

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