views:

397

answers:

1

I have a custom class I created, say MyClass. Now how to add a reference to MyClass's reference as second parameter in the combo box below:

this->ui->comboBox->addItem("item-1", );

Purpose is to when item changed even is fired, i want to get that specific class instance of MyClass and process accordingly.

+3  A: 

First you need to use Q_DECLARE_METATYPE(MyClass*), so that the type can be used in QVariant. Then you can add the item like this:

this->ui->comboBox->addItem("item-1", QVariant::fromValue(myClass));

And get it back:

this->ui->combobox->itemData(x).value<MyClass*>;
Lukáš Lalinský