How to save the widgets load using UiLoader?
-
Is it possible to save the widgets load using
UiLoader
into aui
variable likeUi::MainWindowClass *ui;
?UiLoader loader; QFile file(":/file.ui"); file.open(QIODevice::ReadOnly); QWidget* form = loader.load(&file);
Currently i'm getting widget per widget like:
QFrame* frame = form->findChild<QFrame*>("frame"); QLabel* label = form->findChild<QLabel*>("label");
How to save all widgets at once into a variable like
Ui::MyClass *form;
, in which then could be accessed like
form_ui->frame
,form_ui->label
etc -
Is it possible to save the widgets load using
UiLoader
into aui
variable likeUi::MainWindowClass *ui;
?UiLoader loader; QFile file(":/file.ui"); file.open(QIODevice::ReadOnly); QWidget* form = loader.load(&file);
Currently i'm getting widget per widget like:
QFrame* frame = form->findChild<QFrame*>("frame"); QLabel* label = form->findChild<QLabel*>("label");
How to save all widgets at once into a variable like
Ui::MyClass *form;
, in which then could be accessed like
form_ui->frame
,form_ui->label
etc@Kattia
C++ being a compiled language you cannot do this, you cannot create variables at runtime, depending on what is in a file. (Python could, but not C++.)To get variables at runtime that is why you run
uic
on the.ui
file at build time. Which produces aui_...h
file defining the class forui
with individually named variables for each widget. No morefindChild<>()
calls. So why are you loading the.ui
file viaUiLoader::load()
dynamically at runtime instead of letting it get processed viauic
at compile-time?