[SOLVED] Editable QComboBox get manually inserted value



  • Hi all,
    I'm quite new to Qt programming, so this could seem an awkward question. I've got a QComboBox editable, and in my code when the user clicks a button the slot does the following:

    @
    QString eventID = ui->typeCombo->itemText( ui->typeCombo->currentIndex() );
    @

    the problem is that this not working if the user has manually typed a string in the combobox, and has not hit the RETURN key (so to add the string to the combobox). The result in this case is null. Is there a way to get the user typed value even if the combo does not loose focus and to add it to the combo?

    Thanks


  • Moderators

    Welcome to the forum.

    "This is probably what you need ":http://doc.qt.nokia.com/4.7/qcombobox.html#currentText-prop



  • Why not use:
    @
    QString eventID = ui->typeCombo->currentText();
    @

    instead?

    Note: please use @ tags around code sections to enable code formatting.



  • Thanks, it works!


  • Moderators

    Be sure and add [Solved] to the beginning of your thread title if it's solved. Thanks!


Log in to reply
 

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