Nominate our 2022 Qt Champions!

Pointers in QML?

  • Hi,
    I have a question about objects in QML, I couldn't find any information on the internet.
    Lets say I have a class "A" that inherits of QDeclarativeItem.
    I can insatnciate perfectlly my class A and I can work with it on QML with no problem at al.
    But I have a method (in C++) of another class that takes a A** as an argument.
    How can I pass a pointer to a QML Item to this method? If I just put "&m" (m is the id of my instance of A), it does not compile.
    Any clue?

    Thank you!

  • Moderators

    QML works using meta-object information only. You can pass a QObject pointer between methods and then use qobject_cast<>() to get an object of your A class (or, if you prefer, you can simply use the meta information to interact with the QObject).

Log in to reply