QComboBox* comboBox = new QComboBox(this); comboBox->addItem("Option 1"); comboBox->addItem("Option 2"); comboBox->addItem("Option 3"); QString currentText = comboBox->itemText(comboBox->currentIndex()); qDebug() << "Current selection: " << currentText;
QComboBox* comboBox = new QComboBox(this); comboBox->addItem("Option 1"); comboBox->addItem("Option 2"); comboBox->addItem("Option 3"); comboBox->setItemText(1, "New Option 2");In this example, a QComboBox is created and three items are added to it. The setItemText method is then used to change the text of the second item to "New Option 2". These examples use the Qt library.