Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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

  • Moderators

    Use Q_ENUM_NS to register an enum inside a namespace.



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


Log in to reply