Nominate our 2022 Qt Champions!

Auto-wrapping non-QObject types when passing to QML

  • Hello!

    Is it possible to automatically convert between two non-QObject user-defined types (one is C++-friendly, other is QML-friendly) when passing them to/from QML, similar to how QVector, QList etc. are wrapped and unwrapped as Array-like JavaScript objects?


  • I am 99% sure this is not possible.

    For a type to be usable in QML it's members, how to access them, etc. needs to be made available to the QML engine.
    This happens through the QT Meta Object System.

    To provide some C++ data or functionality to QML, it must be made available from a QObject-derived class.

    You could probably implement a set of macros which combine conventions of your codbase with QT macros to create wrapper types around your types which also derive from QObject.

  • Have you looked at this page?

Log in to reply