设为首页 加入收藏

TOP

Qt自定义对象导入JavaScript脚本使用(六)
2015-02-02 14:10:32 来源: 作者: 【 】 浏览:81
Tags:定义 对象 导入 JavaScript 脚本 使用
Property(this->get_moudle_name().c_str(), qcmu);



? ? add_fun(this->get_moudle_name().c_str(),? "connect",? ? ? ? D_CONNECT? ? ? );
? ? add_fun(this->get_moudle_name().c_str(),? "close",? ? ? ? ? ? D_CLOSE? ? ? );
? ? add_fun( this->get_moudle_name().c_str(),? "send",? ? ? ? ? ? ? D_SEND? ? ? );
? ? add_fun(this->get_moudle_name().c_str(),? "receive",? ? ? ? ? D_RECEIVE? ? );
? ? add_fun(this->get_moudle_name().c_str(),? "ping",? ? ? ? ? ? ? D_PING? ? ? );
? ? add_fun(this->get_moudle_name().c_str(),? "sleep",? ? ? ? ? ? D_SLEEP? ? ? );
? ? add_fun( this->get_moudle_name().c_str(),? "find",? ? ? ? ? ? ? ? D_FIND? ? );
? ? add_fun(this->get_moudle_name().c_str(),? "loopchk",? ? ? ? D_LOOPCHK? ? ? );
? ? add_fun( this->get_moudle_name().c_str(),? "check",? ? ? ? ? ? D_CHECK? ? ? );
? ? add_fun( this->get_moudle_name().c_str(),? "set",? ? ? ? ? ? ? ? D_SET? ? ? );
? ? add_fun(this->get_moudle_name().c_str(),? "stringAdd",? ? ? D_STRINGADD? ? );
? ? add_fun( this->get_moudle_name().c_str(),? "compare",? ? ? D_COMPARE? ? ? );
? ? add_fun( this->get_moudle_name().c_str(),? "add",? ? ? ? ? ? ? ? D_ADD? ? ? );
? ? add_fun(this->get_moudle_name().c_str(),? "loopfind",? ? ? ? D_LOOPFIND? ? );
? ? add_fun( this->get_moudle_name().c_str(),? "change",? ? ? ? ? D_CHANGE? ? ? );
}


?



string STT_Basic_Moudle::get_moudle_name() const
{
? ? return "STT_Basic_Moudle";
}


?


?


string get_stt_variable(int test_id, string key)
{
? ? return (*STT_Basic_Moudle::STT_G_Test_Info)[test_id].variable_map[key];
}



void set_stt_variable(int test_id, string key, string value)
{
? ? (*STT_Basic_Moudle::STT_G_Test_Info)[test_id].variable_map.insert(std::pair(key,value));
}


?


?


void add_fun(const char *moudle_name, const char *fun_name, const char *fun_describe)
{


? ? if((*STT_Basic_Moudle::STT_G_Test_Fun_Info).find(fun_name)==(*STT_Basic_Moudle::STT_G_Test_Fun_Info).end())
? ? {
? ? ? ? TEST_FUN_INFO tfi={moudle_name,fun_name,fun_describe};
? ? ? ? (*STT_Basic_Moudle::STT_G_Test_Fun_Info).insert(std::pair(fun_name,tfi));
? ? }
}


3、使用
我的注册时在插件里实现的,调用在主程序里,这样可以n个插件向同一个java script解释器里注册不同的对象
执行完一次可以判断是否有异常,打印异常信息等


?


///
/// \brief G_STT_Interpreter [STT解释器]
///
std::map G_STT_Interpreter;



/* ############################################################################################################# */



bool G_STT_Run_Fun(QString fun_name, int test_id, QString v1, QString v2, QString v3, QString v4, QString v5, QString v6, QString v7, QString v8, QString v9)
{
? ? bool result = false;
? ? TEST_FUN_INFO tfi = G_Test_Fun_Info[fun_name.toStdString()];


? ? if(tfi.fun_name == fun_name.toStdString())
? ? {
? ? ? ? QString script=QString("%1.%2").arg(tfi.modle_name.c_str(),fun_name);


? ? ? ? QScriptValueList args;
? ? ? ? QScriptEngine * eng =? G_STT_Interpreter[test_id];
? ? ? ? args << test_id << v1<? ? ? ? QScriptValue cpp_fun = eng->eva luate(script);
? ? ? ? qDebug()<? ? ? ? QScriptValue value =? cpp_fun.call(QScriptValue(), args);



? ? ? ? if (G_STT_Interpreter[test_id]->hasUncaughtException()){
? ? ? ? ? ? emit STT_Global::mw->signal_add_Log(test_id, G_STT_Interpreter[test_id]->uncaughtException().toString());
? ? ? ? ? ? emit STT_Global::mw->signal_add_Log(test_id,G_STT_Interpreter[test_id]->uncaughtExceptionBacktrace().join("/n"));
? ? ? ? ? ? qDebug()<uncaughtException().toString();
? ? ? ? ? ? qDebug()<uncaughtExceptionBacktrace().join("/n");
? ? ? ? ? ? return false;
? ? ? ? }else{
? ? ? ? ? ? result = value.toBool();
? ? ? ? }


? ? }

首页 上一页 3 4 5 6 下一页 尾页 6/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android 自动更新的实现 下一篇Qt 程序自定义插件

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: