[Qt-interest] QVariant::type() usage for custom QVariant types
Eckhard Jokisch
e.jokisch at orange-moon.de
Thu Jul 28 14:19:55 CEST 2011
Hi,
thanks to Q_DECLARE_METATYPE it is possible to use custom classes as
QVariant.
Now when I use this QVariant I have to check either with
---------------------------------
QVariant v;
if(v.canConvert<myClaas1>())
....
else if(v.canConvert<myClaas2>())
....
else if(v.canConvert<myClaas3>())
....
------------------------------
or I have to lookup v.typeName() in a QStringList to find the index and
then do a switch like this:
---------------------------------
QStringList list;
list.append("myClass1");
list.append("myClass2");
list.append("myClass3");
switch(list.indexOf(v.typeName)
{
.....
}
---------------------------------
How can I use
int i = v.type();
and get a unique and reliable (in terms of usable in a switch/case)
typenumber for my various classes?
More information about the Qt-interest-old
mailing list