【发布时间】:2014-03-13 11:10:15
【问题描述】:
假设我有一个简单的 QML 插件。我定期检查我的对象的一些状态,在这一步我想从 C++ 查询 QML 对象,以这种方式:
插件代码(c++)
class MyItem : public QQuickItem
{
public:
MyItem(QQuickItem *parent = 0) :
QQuickItem(parent)
{}
void timerFunction(SomeObject * obj)
{
// here I need to call QML function to validate my object, may be in this way:
callJSFunction("myFunction",obj); // that's what I need
if(obj->approved) doSomething();
}
}
QML 文件:
MyItem {
id: myItem
property bool someProperty
function myFunction(obj)
{
obj.approved = someProperty;
}
}
我不能仅仅因为对 JS 的调用必须以同步方式来使用信号。我的意思是我需要的是:
- 在 C++ 代码中,定时器调用函数 timerFunction() 并带有要验证的对象
- 在 timerFunction() 内部调用 JS 函数并返回结果
- 之后我继续执行 timerFunction()
所以我的问题 - 有没有办法从 C++ 插件对象调用 JS 函数?
【问题讨论】:
标签: c++ plugins qml qquickitem