QT: load .ui at run time

Dynamic dialogs are dialogs that are created from Qt Designer .ui files at run-time. Instead of converting
the .ui file to C++ code using uic, we can load the file at run-time using the QUiLoader class:

 

QUiLoader uiLoader;
QFile file("sortdialog.ui");
QWidget *sortDialog = uiLoader.load(&file);
if (sortDialog) {
...
}

 

We can access the form's child widgets using QObject::findChild<T>():
QComboBox *primaryColumnCombo =
sortDialog->findChild<QComboBox *>("primaryColumnCombo");
if (primaryColumnCombo) {
...
}

你可能感兴趣的:(QT: load .ui at run time)