I'm just starting Qt5 using QtCreator, and I have a question regarding changing the name of widgets in design
view.
So, for example, I have a QComboBox
and I I use findChild()
to find it (this is in mainwindow.cpp
):
QComboBox *comboBoxType;
void MainWindow::on_Start_clicked()
{
comboBoxType = ui->stackedWidget->findChild<QComboBox *>("typeComboBox", Qt::FindChildrenRecursively);
comboBoxType->addItem("Hash");
comboBoxType->addItem("Hash2");
}
But when I changed the name of the the widget from typeComboBox
to typeBox
in design
view, for instance, the typeComboBox
name in mainwindow.cpp
wasn't changed, and led to an obvious crash:
02:32:37: The program has unexpectedly finished.
02:32:37: The process was ended forcefully.
02:32:37: D:\...\build-cryptog-Desktop_Qt_5_15_2_MinGW_64_bit-Debug\debug\cryptog.exe crashed.
Is there any ways of changing/updating both name, in .ui
and mainwindow.cpp
simultaneously, or is there a better way other than manually typing in the name in mainwindow.cpp
, so that I don't have to go find the culprit in code after I change something in design
view?
In QtCreator you can use the Advanced Find menu (Ctrl+Shift+F) to do a find and replace operation across all files in the project.
Enable the options "Case sensitive" and "Whole words only" to limit the match to the exact name.