本文整理汇总了C++中QScriptValue::toInt32方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::toInt32方法的具体用法?C++ QScriptValue::toInt32怎么用?C++ QScriptValue::toInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::toInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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));
}
}
示例2: 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());
}
}
示例3: fromScriptValueEntityReference
void fromScriptValueEntityReference(const QScriptValue &obj, EntityReference &s)
{
if (obj.isString())
s.ref = obj.toString();
else
{
if (!obj.property("ref").isValid())
LogError("Can't convert QScriptValue to EntityReference! QScriptValue does not contain ref attribute!");
else
{
QScriptValue ref = obj.property("ref");
if (ref.isNull())
s.ref = ""; // Empty the reference
else if (ref.isString())
s.ref = ref.toString();
else if (ref.isQObject())
{
// If the object is an Entity, call EntityReference::Set() with it
Entity* entity = dynamic_cast<Entity*>(ref.toQObject());
s.Set(entity);
}
else if (ref.isNumber() || ref.isVariant())
s.ref = QString::number(ref.toInt32());
else
LogError("Can't convert QScriptValue to EntityReference! Ref attribute is not null, string, a number, or an entity");
}
}
}
示例4: getTypeOfScript
int ScriptManager::getTypeOfScript(QString strScriptName)
{
m_pScriptEngine->collectGarbage();
m_pScriptEngine->clearExceptions();
m_pScriptEngine->setGlobalObject(m_globalObjects[strScriptName]);
QScriptValue retValue = m_pScriptEngine->evaluate("getTypeOfScript();");
if(m_pScriptEngine->hasUncaughtException())
{
QMessageBox::critical(g_pWndMain, tr("Visual graph editor"), tr("File: %1\nLine: %2\n%3").arg(strScriptName + ".js").arg(m_pScriptEngine->uncaughtExceptionLineNumber()).arg(m_pScriptEngine->uncaughtException().toString()));
m_globalObjects.remove(strScriptName);
}
else
{
int retValueInt32 = retValue.toInt32();
if(retValueInt32 < 0 || retValueInt32 > 2)
{
m_globalObjects.remove(strScriptName);
return -1;
}
else
return retValueInt32;
}
return -1;
}
示例5: Initialize
int PlugScript::Initialize()
{
QScriptValue value = mScriptEngine.evaluate("2 * 2");
qDebug() << value.toInt32();
return 0;
}
示例6: setProperty
void ByteArrayClass::setProperty(QScriptValue &object,
const QScriptString &name,
uint id, const QScriptValue &value) {
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
if (!ba)
return;
if (name == length) {
resize(*ba, value.toInt32());
} else {
qint32 pos = id;
if (pos < 0)
return;
if (ba->size() <= pos)
resize(*ba, pos + 1);
(*ba)[pos] = char(value.toInt32());
}
}
示例7: spanAngle
QScriptValue PHIEllipseItem::spanAngle( const QScriptValue &v )
{
if ( !isServerItem() ) return scriptEngine()->undefinedValue();
if ( !v.isValid() ) return realSpanAngle();
setSpanAngle( v.toInt32() );
setDirtyFlag( DFDoNotCache );
return self();
}
示例8: construct
QScriptValue ByteArrayClass::construct(QScriptContext *ctx, QScriptEngine *) {
ByteArrayClass *cls = qscriptvalue_cast<ByteArrayClass*>(ctx->callee().data());
if (!cls)
return QScriptValue();
QScriptValue arg = ctx->argument(0);
if (arg.instanceOf(ctx->callee()))
return cls->newInstance(qscriptvalue_cast<QByteArray>(arg));
int size = arg.toInt32();
return cls->newInstance(size);
}
示例9: 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);
}
}
示例10: setProperty
void TimerClass::setProperty(QScriptValue &object,
const QScriptString &name,
uint /*id*/, const QScriptValue &value) {
QTimer *timer = qscriptvalue_cast<QTimer*>(object.data());
qDebug() << "Value after de-varianting setProperty: " << timer << name;
if (!timer)
return;
if (name == _interval) {
timer->setInterval(value.toInt32());
} else if (name == _singleShot) {
timer->setSingleShot(value.toBoolean());
}
}
示例11: construct
QScriptValue post_data_list_class::construct(QScriptContext *ctx, QScriptEngine *eng)
{
post_data_list_class *cls = qscriptvalue_cast<post_data_list_class*>(ctx->callee().data());
if (!cls)
return QScriptValue();
QScriptValue arg = ctx->argument(0);
if (arg.instanceOf(ctx->callee()))
return cls->newInstance(qscriptvalue_cast<http_data_list>(arg));
int size = arg.toInt32();
return cls->newInstance();
}
示例12: 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();
}
示例13: 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);
}
}
}
示例14: lineNumber
void tst_QScriptContext::lineNumber()
{
QScriptEngine eng;
QScriptValue result = eng.evaluate("try { eval(\"foo = 123;\\n this[is{a{syntax|[email protected]#$%@#% \"); } catch (e) { e.lineNumber; }", "foo.qs", 123);
QVERIFY(!eng.hasUncaughtException());
QVERIFY(result.isNumber());
QCOMPARE(result.toInt32(), 2);
result = eng.evaluate("foo = 123;\n bar = 42\n0 = 0");
QVERIFY(eng.hasUncaughtException());
QCOMPARE(eng.uncaughtExceptionLineNumber(), 3);
QCOMPARE(result.property("lineNumber").toInt32(), 3);
}
示例15: js_setTimer
/// Special scripting function that registers a timer event. Note: Functions must be passed
/// quoted, otherwise they will be inlined! If a third parameter is passed, this must be an
/// object, which is then passed to the timer. If the object is dead, the timer stops.
static QScriptValue js_setTimer(QScriptContext *context, QScriptEngine *engine)
{
QString funcName = context->argument(0).toString();
QScriptValue ms = context->argument(1);
int player = engine->globalObject().property("me").toInt32();
timerNode node(engine, funcName, player, ms.toInt32());
if (context->argumentCount() == 3)
{
QScriptValue obj = context->argument(2);
node.baseobj = obj.property("id").toInt32();
}
node.type = TIMER_REPEAT;
timers.push_back(node);
return QScriptValue();
}