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. How to pass UI Form object to another class?

How to pass UI Form object to another class?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qframeui object
3 Posts 3 Posters 2.0k 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.
  • K Offline
    K Offline
    kenyanke
    wrote on 10 Feb 2016, 11:30 last edited by kenyanke 2 Oct 2016, 11:31
    #1

    I have a QFrame in the UI designer called SugarView

    I can access SugarView in it's class using ... ui->SugarView

    How would I access that object in main.cpp? so I can pass it as parent to a child. (To display content on it)

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Ni.Sumi
      wrote on 10 Feb 2016, 11:44 last edited by
      #2

      Hello @kenyanke ,
      If you want access the UI object in other class. First include header file(if you created ui file with class and header)and ui file in main.cpp

      #include ui_sugarviewuifile.h
      #include sugarview.h

      and then
      ui_sugarviewui.> access all objects in the ui file/QForm name;

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 10 Feb 2016, 11:45 last edited by
        #3

        hi
        normally you would not allow directly accesses to UI class from outside
        as then all of the program know you have a QFrame in there.

        The better way is simple to create public function
        that sets the data u need in the class that owns
        the UI

        say like
        public:
        SetSugarViewData( QString Name );

        and in cpp you implement it and there u can use
        ui->SugarView

        Then main will talk to "sugerview" via the public functions and has no need to have access to UI->
        directly.

        1 Reply Last reply
        1

        1/3

        10 Feb 2016, 11:30

        • Login

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