在头文件中声明,当comboBox的当前选择项发生变化时,与该槽函数连接的代码将会被执行
void on_comboBox_currentIndexChanged(const QString &arg1);
连接信号与槽
connect(ui->comboBox, &QComboBox::currentTextChanged, this, &MainWindow::on_comboBox_currentIndexChanged);
槽函数实现
void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
{
if(ui->comboBox->currentText()=="数字")
{
ui->comboBox_2->clear();
ui->comboBox_2->addItem("0");
ui->comboBox_2->addItem("1");
}
else if(ui->comboBox->currentText()=="字母")
{
ui->comboBox_2->clear();
ui->comboBox_2->addItem("A");
ui->comboBox_2->addItem("B");
}
else if(ui->comboBox->currentText()=="中文")
{
ui->comboBox_2->clear();
ui->comboBox_2->addItem("你");
ui->comboBox_2->addItem("好");
}
}