Qt Forum

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

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

    General and Desktop
    4
    4
    2179
    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.
    • U
      umen242 last edited by

      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 ?

      1 Reply Last reply Reply Quote 0
      • C
        Chris H last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • G
          goetz last edited by

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

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

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

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