Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using an Q_ENUM from a different class as a Q_PROPERTY in c++ makes QMetaProperty not recognize it as a datatype in QML

Using an Q_ENUM from a different class as a Q_PROPERTY in c++ makes QMetaProperty not recognize it as a datatype in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 866 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QKelteseth
    wrote on last edited by
    #1

    This was posted on reddit 2 weeks ago with no solution:

    Hi guys!

    The issue is pretty much the headline and I' have been trying all day to fix this. The code with the warnings on startup is here:

    https://gitlab.com/kelteseth/ScreenPlay/-/tree/refactor/save-configs
    

    What I essentially did was moving my enums from my settings to my globalvariables class to use the enums in classes that would otherwhise have an circular dependencies. The problem now is that using:

    // Settings.h:52

    Q_PROPERTY(GlobalVariables::FillMode videoFillMode READ videoFillMode WRITE setVideoFillMode NOTIFY videoFillModeChanged)
    

    from

    // globalvariables.h:31
    
    enum class FillMode {
    
    Stretch,
    
    Fill,
    
    Contain,
    
    Cover,
    
    Scale_Down
    
    };
    
    Q_ENUM(FillMode)
    

    Brings these error/warnings

    QMetaProperty::read: Unable to handle unregistered datatype 'GlobalVariables::FillMode' for property 'ScreenPlay::Settings::videoFillMode'
    

    Loc: [jsruntime\qv4qobjectwrapper.cpp:199]

    QMetaProperty::read: Unable to handle unregistered datatype 'GlobalVariables::FillMode' for property 'ScreenPlay::Settings::videoFillMode'
    

    Loc: [jsruntime\qv4qobjectwrapper.cpp:199]

    One for the Installed/Sidebar.qml and one for the Settings/Settings.qml

    • Both are inside the same ScreenPlay namespace
    • The register type calls all happen before any qml is loaded! See app.cpp:90
    • The enums work in qml but still are broken for the c++ property that holds the default FillMode
    • It is the same problem as described here: https://forum.qt.io/topic/75868/q_property-and-enum/3
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Use Q_ENUM_NS to register an enum inside a namespace.

      (Z(:^

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        QKelteseth
        wrote on last edited by
        #3

        @sierdzio thanks looks like this is the way to go ! :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved