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


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

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


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

示例1: setInterval

//! [1]
int Environment::setInterval(const QScriptValue &expression, int delay)
{
    if (expression.isString() || expression.isFunction()) {
        int timerId = startTimer(delay);
        m_intervalHash.insert(timerId, expression);
        return timerId;
    }
    return -1;
}
开发者ID:AtlantisCD9,项目名称:Qt,代码行数:10,代码来源:environment.cpp

示例2: GetObjectInformation

void JavascriptInstance::GetObjectInformation(const QScriptValue &object, QSet<qint64> &ids, uint &valueCount, uint &objectCount, uint &nullCount, uint &numberCount, 
    uint &boolCount, uint &stringCount, uint &arrayCount, uint &funcCount, uint &qobjCount, uint &qobjMethodCount)
{
    if (!ids.contains(object.objectId()))       
        ids << object.objectId();
    
    QScriptValueIterator iter(object);
    while(iter.hasNext()) 
    {
        iter.next();
        QScriptValue v = iter.value();

        if (ids.contains(v.objectId()))
            continue;
        ids << v.objectId();
        
        valueCount++;
        if (v.isNull())
            nullCount++;

        if (v.isNumber())
            numberCount++;
        else if (v.isBool())
            boolCount++;
        else if (v.isString())
            stringCount++;
        else if (v.isArray())
            arrayCount++;
        else if (v.isFunction())
            funcCount++;
        else if (v.isQObject())
            qobjCount++;
        
        if (v.isObject())
            objectCount++;

        if (v.isQMetaObject())
            qobjMethodCount += v.toQMetaObject()->methodCount();
        
        // Recurse
        if ((v.isObject() || v.isArray()) && !v.isFunction() && !v.isString() && !v.isNumber() && !v.isBool() && !v.isQObject() && !v.isQMetaObject())
            GetObjectInformation(v, ids, valueCount, objectCount, nullCount, numberCount, boolCount, stringCount, arrayCount, funcCount, qobjCount, qobjMethodCount);
    }
}
开发者ID:360degrees-fi,项目名称:tundra,代码行数:44,代码来源:JavascriptInstance.cpp

示例3: fromScriptValue

static JSAgentWatchData fromScriptValue(const QString &expression,
                                        const QScriptValue &value)
{
    static const QString arrayStr = QCoreApplication::translate
            ("Debugger::JSAgentWatchData", "[Array of length %1]");
    static const QString undefinedStr = QCoreApplication::translate
            ("Debugger::JSAgentWatchData", "<undefined>");

    JSAgentWatchData data;
    data.exp = expression.toUtf8();
    data.name = data.exp;
    data.hasChildren = false;
    data.value = value.toString().toUtf8();
    data.objectId = value.objectId();
    if (value.isArray()) {
        data.type = "Array";
        data.value = arrayStr.arg(value.property(QLatin1String("length")).toString()).toUtf8();
        data.hasChildren = true;
    } else if (value.isBool()) {
        data.type = "Bool";
        // data.value = value.toBool() ? "true" : "false";
    } else if (value.isDate()) {
        data.type = "Date";
        data.value = value.toDateTime().toString().toUtf8();
    } else if (value.isError()) {
        data.type = "Error";
    } else if (value.isFunction()) {
        data.type = "Function";
    } else if (value.isUndefined()) {
        data.type = undefinedStr.toUtf8();
    } else if (value.isNumber()) {
        data.type = "Number";
    } else if (value.isRegExp()) {
        data.type = "RegExp";
    } else if (value.isString()) {
        data.type = "String";
    } else if (value.isVariant()) {
        data.type = "Variant";
    } else if (value.isQObject()) {
        const QObject *obj = value.toQObject();
        data.type = "Object";
        data.value += '[';
        data.value += obj->metaObject()->className();
        data.value += ']';
        data.hasChildren = true;
    } else if (value.isObject()) {
        data.type = "Object";
        data.hasChildren = true;
        data.value = "[Object]";
    } else if (value.isNull()) {
        data.type = "<null>";
    } else {
        data.type = "<unknown>";
    }
    return data;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:56,代码来源:qjsdebuggeragent.cpp

示例4: currentImportScopeName

static QString currentImportScopeName(QScriptContext *context)
{
    for (; context; context = context->parentContext()) {
        QScriptValue v = context->thisObject()
                .property(StringConstants::importScopeNamePropertyInternal());
        if (v.isString())
            return v.toString();
    }
    return QString();
}
开发者ID:BumblingCoder,项目名称:qbs,代码行数:10,代码来源:rulecommands.cpp

示例5: toString

void tst_QScriptContext::toString()
{
    QScriptEngine eng;
    eng.globalObject().setProperty("parentContextToString", eng.newFunction(parentContextToString));
    QScriptValue ret = eng.evaluate("function foo(first, second, third) {\n"
                                    "    return parentContextToString();\n"
                                    "}; foo(1, 2, 3)", "script.qs");
    QVERIFY(ret.isString());
    QCOMPARE(ret.toString(), QString::fromLatin1("foo(first = 1, second = 2, third = 3) at script.qs:2"));
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:10,代码来源:tst_qscriptcontext.cpp

示例6: if

    QColor convert_script_value_f<QColor>::operator()( QScriptEngine *,
						     const QScriptValue & args ) const
    {
	int r = 0;
	int g = 0;
	int b = 0;
	qreal a = 255;
	QScriptValue obj;
	bool smellArray = ( args.isArray() ||
			    ! args.property("length").isUndefined() );
	if( smellArray )
	{
	    obj = args.property(0);
	}
	else if( args.isObject() )
	{
	    obj = args;
	}

	if( smellArray && !obj.isObject() )
	{
#define ARG(X) args.property(X).toInt32()
	    int argc = args.property("length").toInt32();
	    QScriptValue arg = args.property(0);
	    if( (1 == argc) && arg.isString() )
	    {
		return QColor( arg.toString() );
	    }
	    r = (argc > 0) ? ARG(0) : 0;
	    g = (argc > 1) ? ARG(1) : 0;
	    b = (argc > 2) ? ARG(2) : 0;
	    a = (argc > 3)
		? args.property(3).toNumber()
		: 255.0;
#undef ARG
	}
	else
	{
#define ARG(X) obj.property(X).toInt32()
	    r = ARG("red");
	    g = ARG("green");
	    b = ARG("blue");
#undef ARG
	    QScriptValue av( obj.property("alpha") );
	    if( ! av.isUndefined() )
	    {
		a = av.toNumber();
	    }
	}
	QColor c( r, g, b );
	if( a <= 1.0 ) c.setAlphaF(a);
	else c.setAlpha( int(a) );
	return c;
    }
开发者ID:Mr-Kumar-Abhishek,项目名称:qboard,代码行数:54,代码来源:ScriptQt.cpp

示例7: fromScriptValueAssetReference

void fromScriptValueAssetReference(const QScriptValue &obj, AssetReference &s)
{
    if (obj.isString())
        s.ref = obj.toString();
    else
    {
        if (!obj.property("ref").isValid() || !obj.property("ref").isString())
            LogError("Can't convert QScriptValue to AssetReference! QScriptValue is not a string and it doesn't contain a ref attribute!");
        s.ref = obj.property("ref").toString();
        s.type = obj.property("type").toString();
    }
}
开发者ID:katik,项目名称:naali,代码行数:12,代码来源:ScriptCoreTypeDefines.cpp

示例8: qColorFromScriptValue

void qColorFromScriptValue(const QScriptValue& object, QColor& color) {
    if (object.isNumber()) {
        color.setRgb(object.toUInt32());
    
    } else if (object.isString()) {
        color.setNamedColor(object.toString());
            
    } else {
        QScriptValue alphaValue = object.property("alpha");
        color.setRgb(object.property("red").toInt32(), object.property("green").toInt32(), object.property("blue").toInt32(),
            alphaValue.isNumber() ? alphaValue.toInt32() : 255);
    }
}
开发者ID:Adrianl3d,项目名称:hifi,代码行数:13,代码来源:RegisteredMetaTypes.cpp

示例9: get

QScriptValue UniversalInputDialogScript::get(const QScriptValue& id){
	if (id.isNumber()) {
		int i = id.toInt32();
		if (i < 0 || i > properties.size()) return QScriptValue();
		return engine->newVariant(properties[i].valueToQVariant());
	}
	if (id.isString()) {
		QString sid = id.toString();
		foreach (const ManagedProperty& mp, properties)
			if (mp.name == sid) 
				return engine->newVariant(mp.valueToQVariant());
		return QScriptValue();
	}
开发者ID:svn2github,项目名称:texstudio-trunk,代码行数:13,代码来源:scriptengine.cpp

示例10: animVariantMapFromScriptValue

void AnimVariantMap::animVariantMapFromScriptValue(const QScriptValue& source) {
    if (QThread::currentThread() != source.engine()->thread()) {
        qCWarning(animation) << "Cannot examine Javacript object from non-script thread" << QThread::currentThread();
        Q_ASSERT(false);
        return;
    }
    // POTENTIAL OPTIMIZATION: cache the types we've seen. I.e, keep a dictionary mapping property names to an enumeration of types.
    // Whenever we identify a new outbound type in animVariantMapToScriptValue above, or a new inbound type in the code that follows here,
    // we would enter it into the dictionary. Then switch on that type here, with the code that follow being executed only if
    // the type is not known. One problem with that is that there is no checking that two different script use the same name differently.
    QScriptValueIterator property(source);
    // Note: QScriptValueIterator iterates only over source's own properties. It does not follow the prototype chain.
    while (property.hasNext()) {
        property.next();
        QScriptValue value = property.value();
        if (value.isBool()) {
            set(property.name(), value.toBool());
        } else if (value.isString()) {
            set(property.name(), value.toString());
        } else if (value.isNumber()) {
            int asInteger = value.toInt32();
            float asFloat = value.toNumber();
            if (asInteger == asFloat) {
                set(property.name(), asInteger);
            } else {
                set(property.name(), asFloat);
            }
        } else { // Try to get x,y,z and possibly w
            if (value.isObject()) {
                QScriptValue x = value.property("x");
                if (x.isNumber()) {
                    QScriptValue y = value.property("y");
                    if (y.isNumber()) {
                        QScriptValue z = value.property("z");
                        if (z.isNumber()) {
                            QScriptValue w = value.property("w");
                            if (w.isNumber()) {
                                set(property.name(), glm::quat(w.toNumber(), x.toNumber(), y.toNumber(), z.toNumber()));
                            } else {
                                set(property.name(), glm::vec3(x.toNumber(), y.toNumber(), z.toNumber()));
                            }
                            continue; // we got either a vector or quaternion object, so don't fall through to warning
                        }
                    }
                }
            }
            qCWarning(animation) << "Ignoring unrecognized data" << value.toString() << "for animation property" << property.name();
            Q_ASSERT(false);
        }
    }
}
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:51,代码来源:AnimVariant.cpp

示例11: hostInfo_Ready

void ScriptEngine::hostInfo_Ready(const QHostInfo &myInfo)
{
    QScriptValue myVal = myHostLookups.take(myInfo.lookupId());
    if(myVal.isString()) {
        QString info = myInfo.hostName();
        eval("var name = '"+info+"';"+myVal.toString());
    } else {
        if(myVal.isFunction()) {
            QScriptValueList arguments;
            arguments << QString(myInfo.hostName());
            myVal.call(QScriptValue(), arguments);
        }
    }
}
开发者ID:ElementsPO,项目名称:pokemon-online,代码行数:14,代码来源:scriptengine.cpp

示例12: Video

void YT3ListParser::parseItem(const QScriptValue &item) {
    Video *video = new Video();

    QScriptValue id = item.property("id");
    if (id.isString()) video->setId(id.toString());
    else {
        QString videoId = id.property("videoId").toString();
        video->setId(videoId);
    }

    QScriptValue snippet = item.property("snippet");

    bool isLiveBroadcastContent = snippet.property("liveBroadcastContent").toString() != QLatin1String("none");
    if (isLiveBroadcastContent) {
        delete video;
        return;
    }

    QString publishedAt = snippet.property("publishedAt").toString();
    QDateTime publishedDateTime = QDateTime::fromString(publishedAt, Qt::ISODate);
    video->setPublished(publishedDateTime);

    video->setChannelId(snippet.property("channelId").toString());

    video->setTitle(snippet.property("title").toString());
    video->setDescription(snippet.property("description").toString());

    QScriptValue thumbnails = snippet.property("thumbnails");
    video->setThumbnailUrl(thumbnails.property("medium").property("url").toString());
    video->setMediumThumbnailUrl(thumbnails.property("high").property("url").toString());

    video->setChannelTitle(snippet.property("channelTitle").toString());

    // These are only for "videos" requests

    QScriptValue contentDetails = item.property("contentDetails");
    if (contentDetails.isObject()) {
        QString isoPeriod = contentDetails.property("duration").toString();
        int duration = DataUtils::parseIsoPeriod(isoPeriod);
        video->setDuration(duration);
    }

    QScriptValue statistics = item.property("statistics");
    if (statistics.isObject()) {
        uint viewCount = statistics.property("viewCount").toUInt32();
        video->setViewCount(viewCount);
    }

    videos.append(video);
}
开发者ID:dairdev,项目名称:minitube,代码行数:50,代码来源:yt3listparser.cpp

示例13: loadScript

/*
 * loadScript 方法
 * @param string  js路径(支持本地路径以及http与https协议下远程js获取)
 * @param function 调用函数
 * @return
 *   如果第二个参数不存在, load 失败,返回 false 。
 *   如果第二个参数不存在, load 成功,则返回 true 。
 *   如果第二参数存在,则立即调用内部函数,返回执行结果。
 *      load的内容将以回调函数参数传入:
 *          @param bool err 表明是否正常读取内容
 *          @param function callback 回一个load函数引用
 */
QScriptValue ScriptBinding::loadScript(QScriptContext *context, QScriptEngine *interpreter)
{
    QScriptValue path = context->argument(0);
    QScriptValue scriptFunc = context->argument(1);

    if (context->argumentCount() == 0)
        return QScriptValue(false);

    if (!path.isString())
        return QScriptValue(false);


    QString pathStr = path.toString().toLower().trimmed();
    QString content = "";
    bool err = false;

    // 如果是 HTTP 、 HTTPS 则尝试从远端获取源码
    if (pathStr.indexOf("http://") == 0 || pathStr.indexOf("https://") == 0 ) {
        QNetworkReply* reply;
        QNetworkAccessManager* manager = new QNetworkAccessManager();
        reply = manager->get(QNetworkRequest(QUrl(pathStr)));

        QEventLoop eventLoop;
        connect(manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
        eventLoop.exec();

        QByteArray responseData;
        responseData = reply->readAll();

        // 通过 Content-Type 来嗅探字节流编码
        // 默认为 utf-8 编码
        QString charset = QString(reply->rawHeader("Content-Type")).toLower();
        QRegExp charsetRegExp("charset=([\\w-]+)\\b");
        int pos = charset.indexOf(charsetRegExp);
        if (pos > 0) {
            if (charsetRegExp.cap().size() < 2) {
                charset = "utf-8";
            } else {
                charset = charsetRegExp.cap(1);
            }

        } else {
            charset = "utf-8";
        }

        QTextStream stream(responseData);
        stream.setCodec(getCodec(charset));
        content = QString(stream.readAll());

    } else {
开发者ID:szanlin,项目名称:berserkJS,代码行数:62,代码来源:scriptbinding.cpp

示例14: getFid

TFrameId Level::getFid(const QScriptValue &arg, QString &err) {
  if (arg.isNumber() || arg.isString()) {
    QString s = arg.toString();
    QRegExp re("(-?\\d+)(\\w?)");
    if (re.exactMatch(s)) {
      int d     = re.cap(1).toInt();
      QString c = re.cap(2);
      TFrameId fid;
      if (c.length() == 1)
#if QT_VERSION >= 0x050500
        fid = TFrameId(d, c[0].unicode());
#else
        fid = TFrameId(d, c[0].toAscii());
#endif
      else
开发者ID:opentoonz,项目名称:opentoonz,代码行数:15,代码来源:scriptbinding_level.cpp

示例15: toStringList

static QStringList toStringList(const QScriptValue &scriptValue)
{
    if (scriptValue.isString()) {
        return QStringList(scriptValue.toString());
    } else if (scriptValue.isArray()) {
        QStringList lst;
        int i = 0;
        forever {
            QScriptValue elem = scriptValue.property(i++);
            if (!elem.isValid())
                break;
            lst.push_back(elem.toString());
        }
        return lst;
    }
开发者ID:BumblingCoder,项目名称:qbs,代码行数:15,代码来源:evaluator.cpp


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