如何在QML/Javascript中使用QVector
?
C++:
我在QML中使用的自定义类。该类包含一个返回已注册ElementType
的QVector
的函数。
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
类(custom)的实例,并尝试获取元素的QVector<ElementType*>
并读取其属性。但是QML无法识别QVector
类型。
//.......
function(){
var elements = custom.getElements()
elements[0].property //?
}