How to pass UI Form object to another class?

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

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

  • Qt Champions 2016

    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
    SetSugarViewData( QString Name );

    and in cpp you implement it and there u can use

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.