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


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

本文整理汇总了C++中QScriptValue::isFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::isFunction方法的具体用法?C++ QScriptValue::isFunction怎么用?C++ QScriptValue::isFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QScriptValue的用法示例。


在下文中一共展示了QScriptValue::isFunction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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

示例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: addFunction

 void addFunction(const QString &name, const QString &code)
 {
     QScriptValue f = m_engine->evaluate(code);
     QBS_ASSERT(f.isFunction(), return);
     m_descriptor.setProperty(QLatin1String("value"), f);
     m_engine->defineProperty(m_proto, name, m_descriptor);
 }
开发者ID:zebbra2014,项目名称:qt-labs-qbs,代码行数:7,代码来源:scriptengine.cpp

示例4: qobjectAsActivationObject

void tst_QScriptContext::qobjectAsActivationObject()
{
    QScriptEngine eng;
    QObject object;
    QScriptValue scriptObject = eng.newQObject(&object);
    QScriptContext *ctx = eng.pushContext();
    ctx->setActivationObject(scriptObject);
    QVERIFY(ctx->activationObject().equals(scriptObject));

    QVERIFY(!scriptObject.property("foo").isValid());
    eng.evaluate("function foo() { return 123; }");
    {
        QScriptValue val = scriptObject.property("foo");
        QVERIFY(val.isValid());
        QVERIFY(val.isFunction());
    }
    QVERIFY(!eng.globalObject().property("foo").isValid());

    QVERIFY(!scriptObject.property("bar").isValid());
    eng.evaluate("var bar = 123");
    {
        QScriptValue val = scriptObject.property("bar");
        QVERIFY(val.isValid());
        QVERIFY(val.isNumber());
        QCOMPARE(val.toInt32(), 123);
    }
    QVERIFY(!eng.globalObject().property("bar").isValid());

    {
        QScriptValue val = eng.evaluate("delete foo");
        QVERIFY(val.isBool());
        QVERIFY(val.toBool());
        QVERIFY(!scriptObject.property("foo").isValid());
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:35,代码来源:tst_qscriptcontext.cpp

示例5: inheritActivationAndThisObject

void tst_QScriptContext::inheritActivationAndThisObject()
{
    QScriptEngine eng;
    eng.globalObject().setProperty("myEval", eng.newFunction(myEval));
    {
        QScriptValue ret = eng.evaluate("var a = 123; myEval('a')");
        QVERIFY(ret.isNumber());
        QCOMPARE(ret.toInt32(), 123);
    }
    {
        QScriptValue ret = eng.evaluate("(function() { return myEval('this'); }).call(Number)");
        QVERIFY(ret.isFunction());
        QVERIFY(ret.equals(eng.globalObject().property("Number")));
    }
    {
        QScriptValue ret = eng.evaluate("(function(a) { return myEval('a'); })(123)");
        QVERIFY(ret.isNumber());
        QCOMPARE(ret.toInt32(), 123);
    }

    // QT-2219
    {
        eng.globalObject().setProperty("a", 123);
        QScriptValue ret = eng.evaluate("(function() { myEval('var a = 456'); return a; })()");
        QVERIFY(ret.isNumber());
        QCOMPARE(ret.toInt32(), 456);
        QEXPECT_FAIL("", "QT-2219: Wrong activation object is returned from native function's parent context", Continue);
        QVERIFY(eng.globalObject().property("a").strictlyEquals(123));
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:30,代码来源:tst_qscriptcontext.cpp

示例6: 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

示例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: function

QScriptValue KateScript::function(const QString &name)
{
  QScriptValue value = global(name);
  if(!value.isFunction())
    return QScriptValue();
  return value;
}
开发者ID:azat-archive,项目名称:kate,代码行数:7,代码来源:katescript.cpp

示例9: 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

示例10: callee

void tst_QScriptContext::callee()
{
    QScriptEngine eng;

    {
        QScriptValue fun = eng.newFunction(get_callee);
        fun.setProperty("foo", QScriptValue(&eng, "bar"));
        eng.globalObject().setProperty("get_callee", fun);

        QScriptValue result = eng.evaluate("get_callee()");
        QCOMPARE(result.isFunction(), true);
        QCOMPARE(result.property("foo").toString(), QString("bar"));
    }

    // callee when toPrimitive() is called internally
    {
        QScriptValue fun = eng.newFunction(store_callee_and_return_primitive);
        QScriptValue obj = eng.newObject();
        obj.setProperty("toString", fun);
        QVERIFY(!obj.property("callee").isValid());
        (void)obj.toString();
        QVERIFY(obj.property("callee").isFunction());
        QVERIFY(obj.property("callee").strictlyEquals(fun));

        obj.setProperty("callee", QScriptValue());
        QVERIFY(!obj.property("callee").isValid());
        obj.setProperty("valueOf", fun);
        (void)obj.toNumber();
        QVERIFY(obj.property("callee").isFunction());
        QVERIFY(obj.property("callee").strictlyEquals(fun));
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:32,代码来源:tst_qscriptcontext.cpp

示例11: worker_include

QScriptValue QDeclarativeInclude::worker_include(QScriptContext *ctxt, QScriptEngine *engine)
{
    if (ctxt->argumentCount() == 0)
        return engine->undefinedValue();

    QString urlString = ctxt->argument(0).toString();
    QUrl url(ctxt->argument(0).toString());
    if (url.isRelative()) {
        QString contextUrl = QScriptDeclarativeClass::scopeChainValue(ctxt, -3).data().toString();
        Q_ASSERT(!contextUrl.isEmpty());

        url = QUrl(contextUrl).resolved(url);
        urlString = url.toString();
    }

    QString localFile = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);

    QScriptValue func = ctxt->argument(1);
    if (!func.isFunction())
        func = QScriptValue();

    QScriptValue result;
    if (!localFile.isEmpty()) {

        QFile f(localFile);
        if (f.open(QIODevice::ReadOnly)) {
            QByteArray data = f.readAll();
            QString code = QString::fromUtf8(data);

            QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
            QScriptValue urlContext = engine->newObject();
            urlContext.setData(QScriptValue(engine, urlString));
            scriptContext->pushScope(urlContext);

            QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -4);
            scriptContext->pushScope(scope);
            scriptContext->setActivationObject(scope);
            QDeclarativeScriptParser::extractPragmas(code);

            engine->evaluate(code, urlString, 1);

            engine->popContext();

            if (engine->hasUncaughtException()) {
                result = resultValue(engine, Exception);
                result.setProperty(QLatin1String("exception"), engine->uncaughtException());
                engine->clearExceptions();
            } else {
                result = resultValue(engine, Ok);
            }
            callback(engine, func, result);
        } else {
            result = resultValue(engine, NetworkError);
            callback(engine, func, result);
        }
    }

    return result;
}
开发者ID:wpbest,项目名称:copperspice,代码行数:59,代码来源:qdeclarativeinclude.cpp

示例12: registerStep

void BotThread::registerStep(QScriptValue function, int frec)
{
    if(function.isFunction())
    {
        m_steps.append(new BotStep(function,frec));
        calcDelay();
    }
}
开发者ID:WecodezFox,项目名称:FoxFramework,代码行数:8,代码来源:botthread.cpp

示例13: setTimeout

int TarryTown::setTimeout(const QScriptValue &expression, int delay) {
    if (expression.isString() || expression.isFunction()) {
         int timerId = startTimer(delay);
         p_timeoutHash.insert(timerId, expression);
         return timerId;
    }
    return -1;
}
开发者ID:jasonknight,项目名称:ichabod,代码行数:8,代码来源:tarrytown.cpp

示例14:

void QContext2DCanvas::addEventListener(const QString &type, const QScriptValue &listener,
                                        bool useCapture)
{
    Q_UNUSED(useCapture);
    if (listener.isFunction()) {
        QScriptValue self = m_env->toWrapper(this);
        self.setProperty("on" + type, listener);
    }
}
开发者ID:cedrus,项目名称:qt4,代码行数:9,代码来源:qcontext2dcanvas.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::isFunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。