#include#include int main(int argc, char *argv[]) { QComboBox comboBox; comboBox.addItem("Option 1"); comboBox.addItem("Option 2"); comboBox.addItem("Option 3"); qDebug() << "Number of options in the combo box: " << comboBox.count(); return 0; }
#includeIn this example, a QComboBox widget is added to a QWidget using a layout manager. Three items are added to the list, and the QWidget is shown on the screen. There is no explicit use of the count() method in this example, but it can be used to get the number of items in the list. The QComboBox class is part of the Qt GUI library.#include #include #include int main(int argc, char *argv[]) { QWidget window; QGridLayout *layout = new QGridLayout(&window); QLabel *label = new QLabel("Choose an option:"); QComboBox *comboBox = new QComboBox(); comboBox->addItem("Option 1"); comboBox->addItem("Option 2"); comboBox->addItem("Option 3"); layout->addWidget(label, 0, 0); layout->addWidget(comboBox, 1, 0); window.setLayout(layout); window.show(); return 0; }