#include#include int main(int argc, char *argv[]) { QApplication app(argc, argv); QComboBox comboBox; comboBox.addItem("Option 1"); comboBox.addItem("Option 2"); comboBox.addItem("Option 3"); // Set the current text of the combo box to "Option 2" comboBox.setCurrentText("Option 2"); comboBox.show(); return app.exec(); }
#includeThis example creates a QStringList object that holds four color options, and then creates a QComboBox object and adds those options to it. It then sets the current text to "Green" using the setCurrentText function and shows the combo box. Package/library: Qt#include int main(int argc, char *argv[]) { QApplication app(argc, argv); QStringList options; options << "Blue" << "Green" << "Red" << "Yellow"; QComboBox comboBox; comboBox.addItems(options); // Set the current text of the combo box to "Green" comboBox.setCurrentText("Green"); comboBox.show(); return app.exec(); }