Using a member function with QScriptEngine::newFunction

眉间皱痕 提交于 2019-12-06 06:06:55
ablaeul

Looking into the official example code, you should do something like this:

MyClass::MyClass() {
    QScriptValue self = engine.newFunction(foo, 0);
    ....
}

EDIT: OK, I looked into the reference a little bit more. The problem is, that you try to pass a method, where a function is needed. As @mosg pointed out, this isn't possible. Either you make foo a static function - or you try the solution in the referenced thread. This means, that you create a new QObject via engine.newQObject.

Solution static method:

class MyClass {
public:
    static QScriptValue foo(QScriptContext*, QScriptEngine*);
    MyClass();
};

...

QScriptValue func = engine.newFunction(MyClass::foo)  
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!