Results 1 to 2 of 2

Thread: Q_DECLARE_METATYPE and qVariantCanConvert

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Q_DECLARE_METATYPE and qVariantCanConvert

    Hi,

    I have the following class in a static lib:

    Qt Code:
    1. class ITGraphic : public QPixmap
    2. {
    3. ....
    4. ....
    5. };
    6.  
    7. Q_DECLARE_METATYPE(ITGraphic);
    To copy to clipboard, switch view to plain text mode 

    Thereafter I am returning ITGraphic object in another static library from model class in data function:

    Qt Code:
    1. QVariant ITPictureList::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid())
    4. return QVariant();
    5.  
    6. if (role == Qt::DecorationRole)
    7. {
    8. ITGraphic *graphic = GetBitmap(index.row());
    9. if(graphic != NULL)
    10. {
    11. QPixmap tmpPixmap = graphic->scaled(iconSize,Qt::KeepAspectRatio);
    12. return QIcon(tmpPixmap);
    13. }
    14. else
    15. return QVariant();
    16. }
    17. else if (role == Qt::UserRole)
    18. {
    19. return *(GetBitmap(index.row()));
    20. }
    21.  
    22. return QVariant();
    23. }
    To copy to clipboard, switch view to plain text mode 

    I am trying to get this object like this:

    QVariant value = picList->data(index,Qt::UserRole);

    Qt Code:
    1. res = qVariantCanConvert<ITGraphic>(value);
    2. ITGraphic pGraphic = qvariant_cast<ITGraphic>(value);
    To copy to clipboard, switch view to plain text mode 

    qVariantCanConvert returns false here and I am not able to get the proper object here. But if I try the following, it works:

    Qt Code:
    1. QPixmap pGraphic = qVariantValue<QPixmap>(picList->data(index, Qt::UserRole));
    To copy to clipboard, switch view to plain text mode 


    Can someone help me, how to get the ITGraphic object here?

    Regards,
    Manoj
    Last edited by wysota; 31st March 2008 at 09:59. Reason: reformatted to look better

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
  •  
Qt is a trademark of The Qt Company.