Qt World Summit: Register Today!

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

  • 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?


  • Lifetime Qt Champion

    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
    ( 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.

  • 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.

  • Lifetime Qt Champion

    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.

Log in to reply