Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to clear the items of comboBox
Qt 6.11 is out! See what's new in the release blog

How to clear the items of comboBox

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 15.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hisong1988
    wrote on last edited by
    #1

    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)
    {
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
    QString GuangdongPro[5]={"广州","揭阳","深圳","佛山","汕头"};
    QString ZhejiangPro[3]={"杭州","宁波","温州"};
    QString HunanPro[2]={"长沙","株洲"};

    if(index==0)
    {
        ui->cityComboBox->clear();
        for(int i=0;i<5;i++)
            ui->cityComboBox->setItemText(i,GuangdongPro[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?

    I am still searching for....

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3chNo
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hisong1988
        wrote on last edited by
        #3

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

        Many thanks.

        I am still searching for....

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved