本文整理汇总了C++中QScriptValue::scriptClass方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::scriptClass方法的具体用法?C++ QScriptValue::scriptClass怎么用?C++ QScriptValue::scriptClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::scriptClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toByteArray
QByteArray FilePrototype::toByteArray(const QScriptValue &value)
{
ByteArrayClass *cls = getByteArrayClass(engine());
return (cls && value.scriptClass() == cls)
? *qscriptvalue_cast<QByteArray*>(value.data())
: value.toString().toUtf8();
}
示例2: newInstance
void tst_QScriptClass::newInstance()
{
QScriptEngine eng;
TestClass cls(&eng);
QScriptValue obj1 = eng.newObject(&cls);
QVERIFY(!obj1.data().isValid());
QVERIFY(obj1.prototype().strictlyEquals(cls.prototype()));
QEXPECT_FAIL("", "classname is not implemented", Continue);
QCOMPARE(obj1.toString(), QString::fromLatin1("[object TestClass]"));
QCOMPARE(obj1.scriptClass(), (QScriptClass*)&cls);
QScriptValue num(&eng, 456);
QScriptValue obj2 = eng.newObject(&cls, num);
QVERIFY(obj2.data().strictlyEquals(num));
QVERIFY(obj2.prototype().strictlyEquals(cls.prototype()));
QCOMPARE(obj2.scriptClass(), (QScriptClass*)&cls);
QScriptValue obj3 = eng.newObject();
QCOMPARE(obj3.scriptClass(), (QScriptClass*)0);
obj3.setScriptClass(&cls);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)&cls);
obj3.setScriptClass(0);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)0);
obj3.setScriptClass(&cls);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)&cls);
TestClass cls2(&eng);
obj3.setScriptClass(&cls2);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)&cls2);
// undefined behavior really, but shouldn't crash
QScriptValue arr = eng.newArray();
QVERIFY(arr.isArray());
QCOMPARE(arr.scriptClass(), (QScriptClass*)0);
QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setScriptClass() failed: cannot change class of non-QScriptObject");
arr.setScriptClass(&cls);
QEXPECT_FAIL("", "Changing class of arbitrary script object is not allowed (it's OK)", Continue);
QCOMPARE(arr.scriptClass(), (QScriptClass*)&cls);
QEXPECT_FAIL("", "Changing class of arbitrary script object is not allowed (it's OK)", Continue);
QVERIFY(!arr.isArray());
QVERIFY(arr.isObject());
}