[Qt-interest] assign ID to QComboBox

Alexandre Beraud aberaud at infflux.com
Thu Mar 26 11:06:24 CET 2009


Well, QComboBox has a currentIndex() function. You can also receive the 
index from the various available signals like currentIndexChanged(int). 
When you fill your combo box, you can add a data to each index. Example:
myCombo->setItemData(i, variantId);
Then, when you want to get the id for the selected element:
int index = myCombo->getCurrentIndex();
QVariant variantId = myCombo->itemData(index);
You can store whatever kind of id you want in the QVariant data.
But maybe the index is enough for your needs.

Regards,

Alex


Matthias Pospiech a écrit :
> Alexandre Beraud schrieb:
>> Hi,
>>
>> You can use the setItemData() function of the QComboBox class.
>>
>>   
> Ok, that has an 'index' as option. But how do I get the index back for 
> the currentRow ?
>
> Matthias
>
>


-- 
BERAUD Alexandre
Ingénieur Développement

Infflux - Informatique & Flux
Tel: 01 49 57 92 00 - Fax : 01 49 57 92 01
Mail: aberaud at infflux.com
Visitez notre site :  www.infflux.com





More information about the Qt-interest-old mailing list