QAlex
30th November 2009, 13:22
Hi all,
I read the documentation about QVariant with the little example that I report here:
QVariant v;
MyCustomStruct c;
if (v.canConvert<MyCustomStruct>())
c = v.value<MyCustomStruct>(v);
v = 7;
int i = v.value<int>(); // same as v.toInt()
QString s = v.value<QString>(); // same as v.toString(), s is now "7"
MyCustomStruct c2 = v.value<MyCustomStruct>(); // conversion failed, c2 is empty
From this, I understand that I can initialize a QVariant variable only with data types supported by QVariant itself. Am I right?
Is there a way to initialize the variable v with a custom type?
Thanks for your anwers! ;)
Alex
I read the documentation about QVariant with the little example that I report here:
QVariant v;
MyCustomStruct c;
if (v.canConvert<MyCustomStruct>())
c = v.value<MyCustomStruct>(v);
v = 7;
int i = v.value<int>(); // same as v.toInt()
QString s = v.value<QString>(); // same as v.toString(), s is now "7"
MyCustomStruct c2 = v.value<MyCustomStruct>(); // conversion failed, c2 is empty
From this, I understand that I can initialize a QVariant variable only with data types supported by QVariant itself. Am I right?
Is there a way to initialize the variable v with a custom type?
Thanks for your anwers! ;)
Alex