Important: Please read the Qt Code of Conduct -

After i create the ui.setup(this) in the main.cpp can i access the GUI widgets from any place in the app

  • can i just include the generated ui *.h file in any class and access the widgets ?
    or i need to save pointers in some singletone ?

  • The widgets are hidden from external code, so no, you cannot access them. In most cases it would be bad practice to do so anyway, it's best to design your class so that you have access functions to the things you need to change. I definitely wouldn't go storing pointers to the widgets anyplace outside the class.

  • If you make the ui member public, you can access it from the outside - provided you have a pointer to the class containing ui. Of course that's C++ voodoo magic only told from mouth to mouth, so keep it secret, please :-)

  • You don't want the widgets to be publicly accessible. Really. You don't.

    Just give your class that contains the widgets a proper public API to do whatever you need to show or read from that class, but do not expose the inner workings of your class to other parts of your application. It will lead to spagetti code, dependencies between unrelated parts of your application (making it very hard to track bugs, add features or change your GUI) and is generally Bad Style(TM).

Log in to reply