让C类包含可从QML访问的信号和一些函数 . 现在,为了在QML中访问该类的成员,我写了类似的东西:
myClass
{
id: abc
x: 100
onXChanged: {console.log ("xx");}
}
假设 x
是实际C类的成员,上面的代码确实有效 .
现在,我有一个C类的对象,即 myClass
在相关的C文件中创建 .
题:
Instead of creating a new object of the same class in QML, is it possible and sensible to access and use the already created C++ object in QML?
1 回答
您可以为此使用上下文属性 . 你会写这样的东西:
然后你可以在qml中访问它,如下所示: