如何在qml中访问cpp里的变量和函数?
如何在main.qml文件里使用main.cpp里的变量和函数?我在qml里直接使用的话会总是报错ReferenceError: Can't find variable --------------------编程问答-------------------- 需要使用QDeclarativeContext::setContextProperty
关于这方面的内容,请参考:
Using QML Bindings in C++ Applications --------------------编程问答--------------------
成功了,谢谢,不过我用的是setContextProperty,你的方向指对了,谢谢! --------------------编程问答-------------------- 我和东西共享出来吧:
//在类体中--------------------编程问答-------------------- google下 qml c++混合编程很多的。。
Q_INVOKABLE const static char a=1;
//在main.cpp中
view.rootContext()->setContextProperty("a",ApplicationData::a);
//在QML中
text:a
补充:移动开发 , Qt