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. After i create the ui.setup(this) in the main.cpp can i access the GUI widgets from any place in the app

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 2.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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

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

        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
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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
          0

          • Login

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