Results 1 to 8 of 8

Thread: QVariant - storing QIcons[]

  1. #1
    Join Date
    Aug 2006
    Posts
    83

    Default QVariant - storing 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??

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QVariant - storing QIcons[]

    You could use a QList<QVariant> where each item is another QList<QVariant> where variants contain QIcons.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QVariant - storing QIcons[]

    Thanks. Now that I see I think I'm gonna realise it with QMap<QString,QVariant> and store it in action's data().

  4. #4
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QVariant - storing QIcons[]

    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

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QVariant - storing QIcons[]

    Quote Originally Posted by moowy
    I must extract char* out of QVariant. I set it with
    action->setData("text");
    action is type QAction.
    Qt Code:
    1. QString str = action->data().toString(); // maybe this is sufficient?
    2. char* ptr = qstrdup(qPrintable(str)); // if not, remember to delete
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. #6
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QVariant - storing QIcons[]

    it must be char* , .toString() is nut sufficient

  7. #7
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVariant - storing QIcons[]

    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>();

  8. #8
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QVariant - storing QIcons[]

    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

Similar Threads

  1. QVariant types support for custom properties
    By Dusdan in forum Qt Tools
    Replies: 9
    Last Post: 11th January 2006, 10:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.