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 example

QML_INTERFACE example

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 764 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.
  • V Offline
    V Offline
    vinci
    wrote on last edited by vinci
    #1

    Hello

    I've already asked a question about QML_INTERFACE on stackoverflow but I feel like this is a pretty specialized topic so I thought I should probably ask again here.

    I've a hard time understanding how QML_INTERFACE and QML_IMPLEMENTS_INTERFACES are supposed to be used. A very basic code example of how I initially thought those macros work can be found over at stackoverflow but spoiler alert, it couldn't get it to work at all.

    What confused me further was a quote from the book "Cross-Platform Development with Qt 6 and Modern C++" which states that:
    QML_INTERFACE registers an existing Qt interface type. The type is not instantiable from QML, and you cannot declare QML properties with it.

    I can't figure out if that's true or false? In case it is true doesn't it kinda defeat the whole purpose of having an interface in the first place? What's the point of having an interface if I can't have it use "virtual properties"?

    I've later figured out that it's perfectly fine to combine the QML_ELEMENT and QML_UNCREATABLE macros to create interfaces which can't be instantiated by the QML engine but solely from C++. From C++ one can then pass base class pointers to concrete implementations to the QML engine. This is more or less what I wanted to achieve, so I'm fine with that.

    That I don't understand QML_INTERFACE still bothers me though. :)

    1 Reply Last reply
    2
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      The point of QML_INTERFACE is that a type can implements multiple of them.
      A QML_INTERFACE should not inherit from QObject, the type which will have QML_IMPLEMENTS_INTERFACE will though.

      I believe it only makes sense to have an interace with virtual functions, not properties.

      1 Reply Last reply
      0
      • JarrodJ Offline
        JarrodJ Offline
        Jarrod
        wrote on last edited by
        #3

        @GrecKo said in QML_INTERFACE example:

        A QML_INTERFACE should not inherit from QObject

        Hi @GrecKo how did you determine this, can you point to some docs for further reading? I'm also confused by how these macros should be used correctly and in which circumstances.

        In my case I have a class A with some functions that are pure virtual. Subclasses of this are registered via qmlRegisterType(). I have another base class B with sub classes that are also registered. B has a property of type A.

        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