Results 1 to 4 of 4

Thread: Expose C++ enum to QML

  1. #1
    Join Date
    Dec 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Expose C++ enum to QML

    I searched but found nothing about this problem. Thanks for any help.

    How to expose C++ enum in a namespace to QML ?

    I've enum Presence in namespace A::B.
    enum Presence used in class C, with declration: Q_ENUMS(A::B::Presence).

    But I don't know how to export and use enum A::B::Presence in QML.

  2. #2
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Expose C++ enum to QML

    i didn't use namespace but i don't think it's managed into qml (i think it is to use in the export of your class)
    to use the enum just type C.presenceValue in the qml

  3. #3
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Expose C++ enum to QML

    Did you find a solution about that problem ?

  4. #4
    Join Date
    Aug 2011
    Location
    Canada
    Posts
    8
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Expose C++ enum to QML

    the Q_ENUMS declaration should exist within a class which inherits QObject, and contains the Q_OBJECT macro.

    then, the simplest method would be to expose an instance of this class via QDeclarativeContext::setContextProperty().

    once referenced as a Q_ENUM, an enumeration instance of that type can be referenced as a standard property by Qt: http://www.maemonokian900.com/maemo-...-enums-in-qml/

Similar Threads

  1. QT enum array
    By angarali06 in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2011, 15:21
  2. How to use QVariant with enum?
    By FinderCheng in forum Qt Programming
    Replies: 1
    Last Post: 25th December 2010, 21:23
  3. How to export enum ?
    By Peppy in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2010, 15:15
  4. How can we convert enum to int?
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2010, 16:08
  5. enum property
    By illuzioner in forum Qt Tools
    Replies: 10
    Last Post: 22nd August 2006, 21:47

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.