Results 1 to 6 of 6

Thread: Simplified problem about enums and QVariants.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Simplified problem about enums and QVariants.

    I don't know if that helps you in any way but here goes:
    Qt Code:
    1. class Cls : public QObject {
    2. Q_OBJECT
    3. public:
    4. enum X {
    5. A, B = 13, C
    6. }
    7. Q_ENUMS(X);
    8.  
    9. };
    10.  
    11. Q_DECLARE_METATYPE(Cls::X)
    12.  
    13. #include "main.moc"
    14.  
    15. int main(){
    16.  
    17. int xMT = qRegisterMetaType<Cls::X>("Cls::X");
    18. qDebug() << "Type id:" << xMT;
    19. QVariant v = qVariantFromValue(Cls::B);
    20. qDebug() << v;
    21. Cls::X x = v.value<Cls::X>();
    22. qDebug() << x;
    23. QMetaEnum en = Cls::staticMetaObject.enumerator(0);
    24. qDebug() << en.value(0) << en.value(1) << en.value(2);
    25. qDebug() << "Key for Cls::B is:" << en.valueToKey(Cls::B);
    26. qDebug() << "Key for v is:" << en.valueToKey(v.value<Cls::X>());
    27. qDebug() << "Key for v is:" << en.valueToKey(*(int*)v.data());
    28. return 0;
    29. }
    To copy to clipboard, switch view to plain text mode 

    and the output:

    text Code:
    1. Type id: 258
    2. QVariant(Cls::X, )
    3. 13
    4. 0 13 14
    5. Key for Cls::B is: B
    6. Key for v is: B
    7. Key for v is: B
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 9th August 2011 at 07:39.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 5
    Last Post: 8th August 2011, 19:41
  2. QString sth between trimmed and simplified
    By pmlody in forum Qt Programming
    Replies: 3
    Last Post: 3rd November 2009, 08:13
  3. Problems with QString::simplified() API
    By montylee in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2009, 04:14
  4. Replies: 1
    Last Post: 15th May 2009, 07:16
  5. How to disply Simplified Chinese in QTextBrowser
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2008, 08:15

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.