Passing Q_GADGET as signal parameter from C++ to QML

前端 未结 1 1390
死守一世寂寞
死守一世寂寞 2020-12-21 05:20

Can\'t get a property of a C++ object inside a QML code. Object is passed as a parameter to the signal.

Expected that in QML, the property text of the <

1条回答
  •  有刺的猬
    2020-12-21 05:59

    The release notes for Qt 5.5 says for the new features:

    • Qt Core
      • You can now have Q_PROPERTY and Q_INVOKABLE within a Q_GADGET, and there is a way to query the QMetaObject of such gadget using the QMetaType system

    Indeed, compiling and running your example with Qt 5.4 gives the same result as yours whereas with Qt 5.5 I got Record correctly recognised, i.e. I got as a result:

    qml: Record(abc)
    qml: abc
    

    Also, as stated in the Q_DECLARE_METATYPE documentation, the type passed to the macro - Record in this case, should provide (1) a public default constructor, (2) a public copy constructor and (3) a public destructor. Since Record is a very simple class, there's no need to provide a copy constructor as the default one is sufficient.

    0 讨论(0)
提交回复
热议问题