How to clear the items of comboBox

  • Hi,everyone.
    Now I have two comboBox:box1,and box2.I want the box2 being changed when the box1 is changing.

    The code below;
    @void MainWindow::on_proComboBox_currentIndexChanged(int index)
    QString GuangdongPro[5]={"广州","揭阳","深圳","佛山","汕头"};
    QString ZhejiangPro[3]={"杭州","宁波","温州"};
    QString HunanPro[2]={"长沙","株洲"};

        for(int i=0;i<5;i++)


    But I found that while I had changed the box1,the old items of the box2 was cleared,and the new items wasn't appeared yet.

    anyone have good idea?

  • You have to use addItem function instead of setItemText. There is no item to set its text after clear function.

  • Oh,t3chNo,you're right. I was confused at that time.

    Many thanks.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.