Hello
I wonder if it's possible to store a table of QIcons[] in QVariant?? I know that you can store one QIcon, but I don't know if you can a table of QIcons??
Hello
I wonder if it's possible to store a table of QIcons[] in QVariant?? I know that you can store one QIcon, but I don't know if you can a table of QIcons??
You could use a QList<QVariant> where each item is another QList<QVariant> where variants contain QIcons.
J-P Nurmi
Thanks. Now that I see I think I'm gonna realise it with QMap<QString,QVariant> and store it in action's data().
Can u help me with another problem:
I must extract char* out of QVariant. I set it with
action->setData("text");
action is type QAction.
Tnx
Originally Posted by moowyQt Code:
char* ptr = qstrdup(qPrintable(str)); // if not, remember to deleteTo copy to clipboard, switch view to plain text mode
J-P Nurmi
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