gri
12th August 2008, 08:23
Hello,
as the Qt docs state QVariant does not call the "operator==" when you compare two variants with custom types.
Is there any way to define a comparison method for these types? I want to put a custom type (boost::smart_ptr) into the QComboBox data which works well for enum's when you cast them to int, otherwise not - and the smart_ptr can't be casted to something else :( Putting this type into the ComboBox works well but i can't use QComboBox::findData() to find my items again ...
QVariant v1 = qVariantFromValue(TestNamespace::TestEnum_TestValu e1);
QVariant v11 = qVariantFromValue(TestNamespace::TestEnum_TestValu e1);
v1 == v11: false
v1 == v1 : true
Thanks for your help and sorry for the bad english :o
Edit:
One way would be to extend undocumented the QVariant::Handler like it's done in QtGui/qguivariant.cpp, but this can only be done from ::qRegisterGuiVariant() and I don't want to modify QVariant itself. Since Qt is not statically linked and qRegisterGuiVariant and qUnregisterGuiVariant are not exported from QtGui, I could "fake" them but that would be an ugly hack ...
as the Qt docs state QVariant does not call the "operator==" when you compare two variants with custom types.
Is there any way to define a comparison method for these types? I want to put a custom type (boost::smart_ptr) into the QComboBox data which works well for enum's when you cast them to int, otherwise not - and the smart_ptr can't be casted to something else :( Putting this type into the ComboBox works well but i can't use QComboBox::findData() to find my items again ...
QVariant v1 = qVariantFromValue(TestNamespace::TestEnum_TestValu e1);
QVariant v11 = qVariantFromValue(TestNamespace::TestEnum_TestValu e1);
v1 == v11: false
v1 == v1 : true
Thanks for your help and sorry for the bad english :o
Edit:
One way would be to extend undocumented the QVariant::Handler like it's done in QtGui/qguivariant.cpp, but this can only be done from ::qRegisterGuiVariant() and I don't want to modify QVariant itself. Since Qt is not statically linked and qRegisterGuiVariant and qUnregisterGuiVariant are not exported from QtGui, I could "fake" them but that would be an ugly hack ...