gpt4 book ai didi

c++ - 如何将类方法转换为 QScriptEngine::FunctionSignature

转载 作者:行者123 更新时间:2023-11-28 05:00:12 26 4
gpt4 key购买 nike

我想通过这个方法:

QScriptValue ScriptProcessContext::construct(QScriptContext * ctx, QScriptEngine *)
{
return this->newInstance();
}

QScriptEngine::newFunction .我尝试了以下选项:

  • 如文档中所示 and also this example code :

    QScriptValue ctor = engine->newFunction(construct);

    错误:

    error C3867: 'ScriptProcessContext::construct': function call missing argument list; use '&ScriptProcessContext::construct' to create a pointer to member
  • 强制转换:

    QScriptValue ctor = engine->newFunction((QScriptEngine::FunctionSignature)construct);

    错误:

    error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'QScriptEngine::FunctionSignature'
  • 将指针转换为成员

    QScriptValue ctor = engine->newFunction(
    (QScriptValue(ScriptProcessContext::*)(QScriptContext *, QScriptEngine *))
    &ScriptProcessContext::construct
    );

    错误:

     error C2664: 'QScriptValue QScriptEngine::newFunction(QScriptEngine::FunctionSignature,int)' : cannot convert parameter 1 from 'QScriptValue (__cdecl ScriptProcessContext::* )(QScriptContext *,QScriptEngine *)' to 'QScriptEngine::FunctionSignature'

那么怎么写才是正确的呢?

最佳答案

您尝试传递一个成员函数。那是不支持的。使用自由函数或静态方法。

请注意,在这两种情况下,您都没有 this 指针。您需要以不需要对象的方式编写函数。

关于c++ - 如何将类方法转换为 QScriptEngine::FunctionSignature,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46222199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com