Qml Interface Property



  • There seems to be a current limitation of not being able to define an interface property in Qml, like you can in C++. Is this a bug, or by design?

    With the below Qml code, you will get an error of "MyInterface is not a type" when trying to declare a property that is an interface.

    In C++
    @
    class MyInterface
    {
    // Class definition
    }

    class MyObject: public QObject
    {
    Q_OBJECT
    Q_PROPERTY( MyInterface* interface READ getInstance() WRITE setInterface() )
    }

    // In main, register interface
    qmlRegisterInterface<MyInterface>( "MyInterface" );
    @

    In Qml

    @
    // This is valid
    MyObject {
    interface: SomeInterfaceInstance {}
    }

    // This isn't valid
    Item {
    property MyInterface: SomeInterfaceInstance {}
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.