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. Qml Interface Property

Qml Interface Property

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 1.1k Views
  • 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.
  • D Offline
    D Offline
    duncanc4
    wrote on last edited by
    #1

    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 {}
    }
    @

    1 Reply Last reply
    0
    • V Offline
      V Offline
      v.v.gl
      wrote on last edited by
      #2

      2024year... problem is still the same

      1 Reply Last reply
      0
      • GrecKoG Online
        GrecKoG Online
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        You have to use the Q_DECLARE_INTERFACE and Q_INTERFACES macros

        1 Reply Last reply
        1

        • Login

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