it must be char* , .toString() is nut sufficient
it must be char* , .toString() is nut sufficient
Have a look at QVariant::setValue.
void QVariant::setValue ( const T & value )
Stores a copy of value. If T is a type that QVariant doesn't support, QMetaType is used to store the value. A compile error will occur if QMetaType doesn't handle the type.
Example:
QVariant v;
v.setValue(5);
int i = v.toInt(); // i is now 5
QString s = v.toString() // s is now "5"
MyCustomStruct c;
v.setValue(c);
...
MyCustomStruct c2 = v.value<MyCustomStruct>();
I tried using that but it failed.
The code that jpn submitted works just fine for me.
QString str = action->data().toString(); // maybe this is sufficient?
char* ptr = qstrdup(qPrintable(str)); // if not, remember to delete
I'm really pleased with this forum as I see that there are a lot of friendly people who are not just trying to be smart but really come with solutions. Tnx
Bookmarks