PDA

View Full Version : How to get the index of row which contains a specific string?



adutzu89
3rd February 2014, 17:29
I have a QComboBox from which I want to extract the index of a row that contains a specific row. How can I acomplish that?
Example:

QSqlQuery qsCat("select categID,numeCateg from categ order by numeCateg");
categorie->addItem("Categorie");
while(qsCat.next()){
categId=qsCat.value("categID").toString();
numeCat=qsCat.value("numeCateg").toString();
categorie->addItem(numeCat,categId);
}

For the example let's say that
categorie->addItem() inserts multiple rows from which I have also
categorie->addItem("Administrator","2")

I would like then to use categorie->setCurrentIndex(int index) where index=index where the item has "Administrator".

Thank you

ChrisW67
3rd February 2014, 21:31
QComboBox::findText() and Qt Assistant or Qt Creator Help (http://qt-project.org/doc/qtcreator-3.0/creator-help.html)

adutzu89
4th February 2014, 12:47
Oh, I'm sorry, appearantly I didn't looked how I should've looked in the documentation.It happens sometimes, thank you for opening my eyes.