Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
查看官方示例代码,您应该执行以下操作:
MyClass::MyClass() { QScriptValue self = engine.newFunction(foo, 0); .... }
编辑:好的,我稍微查看了参考资料。问题是,您尝试传递需要函数的方法。正如@mosg指出的那样,这是不可能的。要么创建foo一个静态函数 - 要么在引用的线程中尝试解决方案。这意味着,您创建一个新的QObjectvia engine.newQObject。
foo
QObject
engine.newQObject
解静态法:
class MyClass { public: static QScriptValue foo(QScriptContext*, QScriptEngine*); MyClass(); }; ... QScriptValue func = engine.newFunction(MyClass::foo)