PDA

View Full Version : Retrieve userData of a comboBox item



jiveaxe
23rd August 2007, 10:04
The manual says:


void QComboBox::addItem ( const QString & text, const QVariant & userData = QVariant() )
//Adds an item to the combobox with the given text, and containing the specified userData. The item is appended to the list of existing items.

but how can i get the userData of a given item?

Bye

marcel
23rd August 2007, 10:09
See QVariant QComboBox::itemData ( int index, int role = Qt::UserRole ) const .

Regards

jiveaxe
23rd August 2007, 10:13
I already tried it but returns text.

Regards

jpn
23rd August 2007, 10:15
And what/how did you add as user data? May we see the addItem() statement?

jiveaxe
23rd August 2007, 10:22
sample code:



QString bookTitle = "Beginning Joomla!";
QString isbn13String = "978-1590598481";
titleComboBox->addItem(bookTitle, isbn13String);

Thanks

marcel
23rd August 2007, 10:24
In this case use :


QString data = titleComboBox->itemData(0).toString();

jiveaxe
23rd August 2007, 10:28
Ok marcel, now works.

Thank you