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.hand then
ui_sugarviewui.> access all objects in the ui file/QForm name; -
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 UIsay like
public:
SetSugarViewData( QString Name );and in cpp you implement it and there u can use
ui->SugarViewThen main will talk to "sugerview" via the public functions and has no need to have access to UI->
directly.
3/3