【发布时间】:2015-06-09 22:19:10
【问题描述】:
我在 C++ 中声明我的对象
class Action : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name)
public:
Action(): QObject(0) {}
QString name() const { return "rem"; }
Q_INVOKABLE void getData() {};
}
并使其对 qml 可用:
engine()->rootContext()->setContextProperty("action", new Action());
如何将javascript函数作为参数传递给getData()方法并在C++端调用该函数?
所以从 QML 的角度来看,它应该是这样的:
action.getData(function(data) { alert(data); });
【问题讨论】: