当前位置: 首页>>代码示例>>C++>>正文


C++ QScriptValue::call方法代码示例

本文整理汇总了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();
}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:28,代码来源:environment.cpp

示例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;
}
开发者ID:ceridian,项目名称:warzone2100,代码行数:34,代码来源:qtscript.cpp

示例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());
    }
}
开发者ID:Auroness,项目名称:PlainText,代码行数:31,代码来源:session.cpp

示例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() );
    }
}
开发者ID:KDAB,项目名称:KDTools,代码行数:28,代码来源:mainwindow.cpp

示例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();
}
开发者ID:akahan,项目名称:qutim,代码行数:28,代码来源:scriptextensionplugin.cpp

示例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());
    }
}
开发者ID:Auroness,项目名称:PlainText,代码行数:26,代码来源:session.cpp

示例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();
                }
            }
        }
    }
}
开发者ID:sunpeng196,项目名称:CuteTorrent,代码行数:26,代码来源:CustomScriptSearchProvider.cpp

示例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);
		}
开发者ID:ohager,项目名称:kantalupe,代码行数:7,代码来源:ScriptEngineApiLevel_1.cpp

示例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();
    }
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:26,代码来源:QtScriptEngine.cpp

示例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();
}
开发者ID:blacksjt,项目名称:autobots,代码行数:25,代码来源:netease_encrypt.cpp

示例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();
}
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:8,代码来源:doc_src_qtscript.cpp

示例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();
}
开发者ID:UIKit0,项目名称:kate,代码行数:28,代码来源:katetemplatescript.cpp

示例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();
}
开发者ID:0xd34df00d,项目名称:Qross,代码行数:26,代码来源:script.cpp

示例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);
    }
}
开发者ID:wpbest,项目名称:copperspice,代码行数:8,代码来源:qdeclarativeinclude.cpp

示例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));
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:9,代码来源:tst_qscriptcontext.cpp


注:本文中的QScriptValue::call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。