如何QVector在 QML/Javascript 中使用?例子:
C++:
我在 QML 中使用的自定义类。该类包括返回QVector注册的函数ElementType
class CustomType : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QVector<ElementType*> getElements();
//.....
}
//.........
qmlRegisterType<CustomType>("CustomComponents", 1, 0, "CustomType");
qmlRegisterType<ElementType>("CustomComponents", 1, 0, "ElementType");
qRegisterMetaType<ElementType*>("ElementType*");
QML:
QML 代码接收类的实例CustomType(自定义)并尝试获取QVector<ElementType*>元素并读取其属性。但是 QML 不能识别QVector类型。
//.......
function(){
var elements = custom.getElements()
elements[0].property //?
}