Results 1 to 8 of 8

Thread: "Enum class"/Q_ENUM use in QML? Cannot read property of undefined

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: "Enum class"/Q_ENUM use in QML? Cannot read property of undefined

    Quote Originally Posted by sedi View Post
    As for the :: syntax: yes, this is what I do from C++
    I'd thought there should be a syntax like: in QML.
    JavaScript doesn't have enums, QML allows you to do something like enums by registering names.
    What you are writing there is an Object or singleton called Enums with a subobject/property DayOfWeek with an enum.
    But that doesn't exist on the C++ side either.

    Quote Originally Posted by sedi View Post
    It seems a bit unsatisfying to either use deprecated stuff or not use the enums in QML at all
    Or you use normal enums instead of enum classes and have comparable support on both language sides.
    Would be my choice.

    Cheers,
    _

  2. #2
    Join Date
    Jul 2016
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: "Enum class"/Q_ENUM use in QML? Cannot read property of undefined

    I've had a similar issue. Does it work if you add

    Qt Code:
    1. qRegisterMetaType<Enums::DayOfWeek >("Enums::DayOfWeek")
    To copy to clipboard, switch view to plain text mode 

    and change the call to:

    Qt Code:
    1. myObject.outputDay(Enums.MONDAY)
    To copy to clipboard, switch view to plain text mode 
    ?

    The one thing that is not so nice about this is that the parameter in the call doesn't refer to DayOfWeek anymore.

    Regards

  3. The following user says thank you to oiaavb for this useful post:

    sedi (1st August 2016)

  4. #3
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: "Enum class"/Q_ENUM use in QML? Cannot read property of undefined

    Yes, absolutely! The loss of the strong typisation is a pity - but at least I can use it :-) Thanks!

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 10:02
  2. Replies: 3
    Last Post: 16th March 2015, 07:31
  3. Cannot assign to non-existent property "lon" lon: "3"
    By TheIndependentAquarius in forum Qt Quick
    Replies: 1
    Last Post: 12th November 2013, 15:50
  4. [SOLVED] QPropertyAnimation "text" property in QLabel
    By AlekseyK in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2010, 18:46
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Tags for this Thread

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.