Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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?

    Thanks,
    Igor



  • 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.

    https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html

    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