Results 1 to 2 of 2

Thread: How to use QVariant with enum?

  1. #1
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use QVariant with enum?

    I want to use an enum as the user data in QComboBox, say MyClass::MyEnum. But when I tried to get this data using QComboBox::itemData(UserRole), I cannot convert it to this enum. I read the docs and add Q_ENUMS(MyEnum) in myclass.h, but it doesn't work. The enum is only a util class's data, there is no need to set it as a property, how should I do if I want to convert QVariant to custom enum?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to use QVariant with enum?

    Look up Q_DECLARE_METATYPE in QMetaType

Similar Threads

  1. How to export enum ?
    By Peppy in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2010, 16:15
  2. How can we convert enum to int?
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2010, 17:08
  3. Replies: 1
    Last Post: 4th December 2009, 18:03
  4. enum property
    By illuzioner in forum Qt Tools
    Replies: 10
    Last Post: 22nd August 2006, 22:47
  5. enum scope
    By illuzioner in forum General Programming
    Replies: 1
    Last Post: 15th February 2006, 06:39

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.