Have dynamic combobox based on changes in another combobox
My application currently has 2 comboboxes on the main form. The first combobox has 14 items, but 5 categories. I would like to list the categories in an additional combobox that I would place on the form above the 14 item combobox. Then populate dynamically the original 14 item combobox (doing a clear()) first) with items based on the category combox selection. I think I've found how to clear and add items, but I don't know how to connect the signal. Any help would be greatly appreciated. Thanks.
Re: Have dynamic combobox based on changes in another combobox
I got it working using a connect slot and a better alternative method too. No need to reply.
Added after 24 minutes:
The connect slot solution is:
Code:
connect(ui
->comboBox, static_cast<void
(QComboBox::*)(const QString &)>
(&QComboBox
::currentIndexChanged),
this,
&MainWindow
::setGames);
An alternative and easier solution is:
Code:
void MainWindow
::on_comboBox_currentTextChanged(const QString &arg1
) {
if (arg1 == "first") {
ui->comboBox_2->clear();
ui->comboBox_2->addItem("1");
}
else if (arg1 == "second") {
ui->comboBox_2->clear();
ui->comboBox_2->addItem("2");
}
else if (arg1 == "third") {
ui->comboBox_2->clear();
ui->comboBox_2->addItem("3");
}
}