本文整理汇总了C++中QScriptValue::call方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::call方法的具体用法?C++ QScriptValue::call怎么用?C++ QScriptValue::call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleEvent
void Environment::handleEvent(QContext2DCanvas *canvas, QKeyEvent *e)
{
QString type;
switch (e->type()) {
case QEvent::KeyPress:
type = "keydown"; break;
case QEvent::KeyRelease:
type = "keyup"; break;
default: break;
}
if (type.isEmpty())
return;
QScriptValue handlerObject;
QScriptValue handler = eventHandler(canvas, type, &handlerObject);
if (!handler.isFunction())
return;
QScriptValue scriptEvent = newFakeDomEvent(type, toWrapper(canvas));
// KeyEvent
scriptEvent.setProperty("isChar", !e->text().isEmpty());
scriptEvent.setProperty("charCode", e->text());
scriptEvent.setProperty("keyCode", FakeDomEvent::qtToDomKey(e->key()));
scriptEvent.setProperty("which", e->key());
handler.call(handlerObject, QScriptValueList() << scriptEvent);
maybeEmitScriptError();
}
示例2: callFunction
// Call a function by name
static bool callFunction(QScriptEngine *engine, const QString &function, const QScriptValueList &args, bool required = false)
{
code_part level = required ? LOG_ERROR : LOG_WARNING;
QScriptValue value = engine->globalObject().property(function);
if (!value.isValid() || !value.isFunction())
{
// not necessarily an error, may just be a trigger that is not defined (ie not needed)
// or it could be a typo in the function name or ...
debug(level, "called function (%s) not defined", function.toUtf8().constData());
return false;
}
int ticks = wzGetTicks();
QScriptValue result = value.call(QScriptValue(), args);
ticks = wzGetTicks() - ticks;
if (ticks > MAX_MS)
{
debug(LOG_SCRIPT, "%s took %d ms at time %d", function.toAscii().constData(), ticks, wzGetTicks());
}
if (engine->hasUncaughtException())
{
int line = engine->uncaughtExceptionLineNumber();
QStringList bt = engine->uncaughtExceptionBacktrace();
for (int i = 0; i < bt.size(); i++)
{
debug(LOG_ERROR, "%d : %s", i, bt.at(i).toAscii().constData());
}
ASSERT(false, "Uncaught exception calling function \"%s\" at line %d: %s",
function.toAscii().constData(), line, result.toString().toAscii().constData());
engine->clearExceptions();
return false;
}
return true;
}
示例3: processSignIn
void Session::processSignIn(const QString &data) {
try {
switch (m_sessionState) {
case SessionClosed:
break;
case SigningIn: {
QScriptValue processSignIn = m_scriptObject.property("processSignIn");
QScriptValueList args;
args.append(data.trimmed());
processSignIn.call(m_scriptObject, args);
break;
}
case SignedIn: {
CommandEvent event(m_player, data);
event.process();
break;
}
}
ScriptEngine *engine = ScriptEngine::instance();
if (engine->hasUncaughtException()) {
LogUtil::logException("Script Exception: %1\n"
"In Session::processSignIn()", engine->uncaughtException());
}
} catch (GameException &exception) {
LogUtil::logError("Exception in Session::processSignIn(): %1", exception.what());
}
}
示例4: loadApplicationData
void MainWindow::loadApplicationData()
{
// Loading the headers
QFile headersFile( m_appDir.absoluteFilePath( QLatin1String("headers.js") ) );
headersFile.open(QFile::ReadOnly);
const QString script = QTextStream( &headersFile ).readAll();
headersFile.close();
QScriptEngine engine;
engine.evaluate(script);
QScriptValue function = engine.globalObject().property( QLatin1String("headers") );
QStringList headers = function.call().toString().split( QLatin1String(", ") );
m_table->setColumnCount(headers.size());
m_table->setHorizontalHeaderLabels(headers);
// Loading the stylesheet
if ( m_appDir.exists( QLatin1String("application.qss") ) ) {
QFile styleFile( m_appDir.absoluteFilePath( QLatin1String("application.qss") ) );
styleFile.open(QFile::ReadOnly);
const QString stylesheet = QTextStream( &styleFile ).readAll();
styleFile.close();
qApp->setStyleSheet(stylesheet);
}
else {
qApp->setStyleSheet( QString() );
}
}
示例5: scriptRequestInfo
QScriptValue scriptRequestInfo(QScriptContext *context, QScriptEngine *engine)
{
if (context->argumentCount() < 2)
return context->throwError("qutim.requestInfo() takes at least 2 arguments");
QObject *object = context->argument(0).toQObject();
if (!object)
return context->throwError("First argument must be QObject");
QScriptValue func = context->argument(1);
if (!func.isFunction())
return context->throwError("Second argument must be callback");
InfoRequestFactory *factory = InfoRequestFactory::factory(object);
QScriptValue errorFunc = context->argument(2);
if (!factory || factory->supportLevel(object) <= InfoRequestFactory::Unavailable) {
if (errorFunc.isFunction()) {
qDebug() << Q_FUNC_INFO;
QScriptValue error = engine->newObject();
error.setProperty(QLatin1String("name"), QLatin1String("NotSupported"));
error.setProperty(QLatin1String("text"), QLatin1String("Unit does not support information request"));
QList<QScriptValue> args;
args << error;
errorFunc.call(errorFunc, args);
}
return engine->undefinedValue();
}
InfoRequest *request = factory->createrDataFormRequest(object);
new ScriptInfoRequest(func, errorFunc, request);
return engine->undefinedValue();
}
示例6: open
void Session::open() {
try {
setSessionState(SigningIn);
ScriptEngine *engine = ScriptEngine::instance();
m_scriptObject = engine->evaluate("new SessionHandler()");
if (engine->hasUncaughtException()) {
LogUtil::logException("Script Exception: %1\n"
"In Session::open()", engine->uncaughtException());
return;
}
QScriptValue setSession = m_scriptObject.property("setSession");
QScriptValueList args;
args.append(engine->toScriptValue(this));
setSession.call(m_scriptObject, args);
if (engine->hasUncaughtException()) {
LogUtil::logException("Script Exception: %1\n"
"In Session::open()", engine->uncaughtException());
}
} catch (GameException &exception) {
LogUtil::logError("Exception in Session::open(): %1", exception.what());
}
}
示例7: parseAsJson
void CustomScriptSearchProvider::parseAsJson(QNetworkReply* pReply)
{
if (m_pEngine)
{
QScriptValue globalObject = m_pEngine->globalObject();
QScriptValue json = globalObject.property("JSON");
if (json.isObject())
{
QScriptValue parseFunk = json.property("parse");
if (parseFunk.isFunction())
{
QString jsonStr = pReply->readAll();
QScriptValue object = parseFunk.call(json, QScriptValueList() << jsonStr);
QScriptValue thisObj = m_scriptVal;
if (thisObj.isObject() && thisObj.isValid())
{
thisObj.setProperty("jsonResult", object);
emit JsonResultReady();
}
}
}
}
}
示例8: leave
void leave(TreeItem * item){
Q_ASSERT(_qengine);
QObject * scriptitem = new ScriptObjectTreeItem(item);
QScriptValue itemvalue = _qengine->newQObject(scriptitem, QScriptEngine::ScriptOwnership);
QScriptValue funcEnd = _qengine->globalObject().property("onLeftItem");
funcEnd.call(QScriptValue(),QScriptValueList() << itemvalue);
}
示例9: printFunction
QScriptValue QtScriptEngine::printFunction(QScriptContext *context, QScriptEngine *engine)
{
QScriptValue debugPrintFunc = engine->globalObject().property("printDebug");
if (debugPrintFunc.isValid())
{
debugPrintFunc.call(context->thisObject(), context->argumentsObject());
}
QString output;
for (int i = 0; i < context->argumentCount(); i++)
{
if (i > 0)
{
output += " ";
}
output += context->argument(i).toString();
}
static_cast<MyQScriptEngine*>(engine)->wrapperEngine->callEventHandlers(
IScriptEngine::Information, NULL, -1, output.toUtf8().constData());
return engine->undefinedValue();
}
示例10: EncryptPassword
QString netease_encrypt::EncryptPassword(const QString& password)
{
QScriptValue global_ob = m_engine->globalObject();
QScriptValue func = global_ob.property("getSP");
if (!func.isValid())
{
return "";
}
QScriptValueList args;
args << password ;
QScriptValue v = func.call(QScriptValue(), args);
if(v.isError()) {//解析js文件是否有错误
QMessageBox::critical(0, "Hello Script",
QString::fromLatin1("%0:%1: %2")
.arg(m_file_name)//文件名
.arg(v.property("lineNumber").toInt32())//错误行号
.arg(v.toString()));//错误信息
return "";
}
return v.toString();
}
示例11: Employee_ctor
//! [37]
QScriptValue Employee_ctor(QScriptContext *context, QScriptEngine *engine)
{
QScriptValue super = context->callee().property("prototype").property("constructor");
super.call(context->thisObject(), QScriptValueList() << context->argument(0));
context->thisObject().setProperty("salary", context->argument(1));
return engine->undefinedValue();
}
示例12: invoke
QString KateTemplateScript::invoke(KateView* view, const QString& functionName, const QString &srcText) {
if(!setView(view))
return QString();
clearExceptions();
QScriptValue myFunction = function(functionName);
if(!myFunction.isValid()) {
return QString();
}
QScriptValueList arguments;
arguments << QScriptValue(m_engine, srcText);
QScriptValue result = myFunction.call(QScriptValue(), arguments);
if(m_engine->hasUncaughtException()) {
displayBacktrace(result, "Error while calling helper function");
return QString();
}
if (result.isNull()) {
return QString();
}
return result.toString();
}
示例13: callFunction
QVariant EcmaScript::callFunction(const QString& name, const QVariantList& args)
{
if( ! d->m_engine && ! d->init() ) {
d->handleException();
return QVariant();
}
QScriptValue obj = d->m_engine->globalObject();
QScriptValue function = obj.property(name);
if( ! function.isFunction() ) {
QString err = QString("No such function '%1'").arg(name);
qrosswarning( QString("EcmaScript::callFunction %1").arg(err) );
setError(err);
return QVariant();
}
QScriptValueList arguments;
foreach(const QVariant &v, args)
arguments << d->m_engine->toScriptValue(v);
QScriptValue result = function.call(obj, arguments);
if( d->m_engine->hasUncaughtException() ) {
d->handleException();
return QVariant();
}
return result.toVariant();
}
示例14: callback
void QDeclarativeInclude::callback(QScriptEngine *engine, QScriptValue &callback, QScriptValue &status)
{
if (callback.isValid()) {
QScriptValue args = engine->newArray(1);
args.setProperty(0, status);
callback.call(QScriptValue(), args);
}
}
示例15: getParentContextCallee
void tst_QScriptContext::parentContextCallee_QT2270()
{
QScriptEngine engine;
engine.globalObject().setProperty("getParentContextCallee", engine.newFunction(getParentContextCallee));
QScriptValue fun = engine.evaluate("(function() { return getParentContextCallee(); })");
QVERIFY(fun.isFunction());
QScriptValue callee = fun.call();
QVERIFY(callee.equals(fun));
}