QComboBox* myComboBox = new QComboBox(); myComboBox->addItem("Option 1"); myComboBox->addItem("Option 2"); myComboBox->addItem("Option 3"); // Clear all items from the QComboBox myComboBox->clear();
void MyClass::clearComboBox(QComboBox* comboBox) { comboBox->clear(); } // Call the clearComboBox function with a reference to a QComboBox object clearComboBox(myComboBox);In this example, we define a new function called "clearComboBox" that takes a QComboBox object as a parameter and clears it using the clear() function. The function can be called from anywhere in the code by passing a reference to a QComboBox object. Package Library: Qt Library.