The syntax above the answer is a little flawed,
use Q_DECLARE_METATYPE (MyClass *) in the MyClass header file so that this type can be used in QVariant.
add the item as follows:
this-> ui-> comboBox-> addItem ("item-1", QVariant :: fromValue (myClass));
And return it: this-> ui-> combobox-> ItemData (x) .value ();
source share