How to display ComboBox item based on value?



  • Hi,

    I'm try to display one of pre-existing values of a combobox.

    ui->genderComboBox->setCurrentIndex(
                    ui->genderComboBox->findData(
                        QString::fromStdString(member->getGender())));
    

    Basically, if member->getGender() returns male or female, I want that to display. The combobox was created using qt designer.

    When I run the code above, a blank item is displayed in the combobox. If I click the drop down arrow, it displays male and female.



  • How about QComboBox::setCurrentText(const QString& text)?

    ui->genderComboBox->setCurrentText(member->getGender());
    

Log in to reply
 

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