Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] After setting default item index of QCombobox will not be updated on GUI
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] After setting default item index of QCombobox will not be updated on GUI

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.2k 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.
  • S Offline
    S Offline
    Snowseeker
    wrote on last edited by
    #1

    Hi,

    I would like to add items to my combobox during starting up my application. And after adding all my items I would like to change the current index to my default. Sadly on the GUI the combox is blank if my program starts up. If I click on the combobox I will see the added items. Do I have to call some update method?

    What I'm wondering too is if don't call setCurrentIndex() method. Then the combox will not be blank and index 0 is visible.

    Thanks in advance for your help.

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    for(UINT8 i = 0; i < ( sizeof(myList)/sizeof(myList[0]) ); i++)
    {
        ui->comboBox->addItem( myList[i] );
    }
    
    
    connect(ui->comboBox, SIGNAL( currentIndexChanged(int) ), this, SLOT( mySlot(int) ) );
    
    
    ui->comboBox->insertSeparator(4);
    emit ui->comboBox->setCurrentIndex(4);
    

    }@

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Welcome to Qt forum.
      @
      emit ui->comboBox->setCurrentIndex(4);
      @

      "setCurrentIndex":http://qt-project.org/doc/qt-5/qcombobox.html#currentIndex-prop is a normal function, no need to use emit.

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Snowseeker
        wrote on last edited by
        #3

        I've taken away the emit but sadly combobox stays still empty in initial state.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Hmm that is because you are setting currentIndex to that of the seperator. Change any one.

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Snowseeker
            wrote on last edited by
            #5

            It's now running. The methods insertSeperator() and setCurrentIndex() should not have the same index. Solution below.

            @ui->comboBox->insertSeparator(4);
            ui->comboBox->setCurrentIndex(4 + 1);@

            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