QML/Javascript中如何使用QVector
? 实施例:QML/Javascript中的QVector
C++:我在QML使用
自定义类。该类包括注册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的返回QVector
功能:
QML代码接收实例CustomType
类(自定义),并尝试获取元素QVector<ElementType*>
并读取其属性。但QML无法识别QVector
类型。
//.......
function(){
var elements = custom.getElements()
elements[0].property //?
}
这不完全是我所需要的。 我已添加: qRegisterMetaType>(“QVector ”); 在QML中,我收到此类型:QVariant(QVector ) 那么,如何访问QVariant内部? –
Svicer
2012-07-31 13:22:29