本文整理汇总了C++中QScriptValue::equals方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::equals方法的具体用法?C++ QScriptValue::equals怎么用?C++ QScriptValue::equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::equals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RunScript
QScriptValue ScriptingTest::RunScript(QString name, QScriptValue expected_value) {
std::cout << "================================================================" << std::endl;
std::cout << "Running script: \"" << dt::Utils::ToStdString(name) << "\"..." << std::endl;
QScriptValue val;
bool this_failed = false;
if(!dt::ScriptManager::Get()->ExecuteScript(name)) {
std::cerr << "Execution of script \"" << dt::Utils::ToStdString(name) << "\" failed." << std::endl;
this_failed = true;
} else {
val = dt::ScriptManager::Get()->GetLastReturnValue();
if(val.isError() && !val.equals(expected_value)) { // error, and no error expected
std::cerr << "ERROR: Script error." << std::endl;
std::cerr << "Message: " << dt::Utils::ToStdString(val.toString()) << std::endl;
this_failed = true;
} else if(!expected_value.isUndefined() && !val.equals(expected_value)) {
std::cerr << "ERROR: Wrong value." << std::endl;
std::cerr << "Returned: " << dt::Utils::ToStdString(val.toString()) << std::endl;
std::cerr << "Expected: " << dt::Utils::ToStdString(expected_value.toString()) << std::endl;
this_failed = true;
}
}
if(!this_failed) {
std::cout << "Script test successful." << std::endl;
} else {
mFailed = true;
}
return val;
}
示例2: 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));
}
}
示例3: 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));
}
示例4: importSimplePlugin
void tst_QScriptExtensionPlugin::importSimplePlugin()
{
QScriptEngine eng;
QCoreApplication::addLibraryPath("plugins");
QVERIFY(eng.importedExtensions().isEmpty());
QStringList available = eng.availableExtensions();
QVERIFY(available.contains("simple"));
QVERIFY(available.contains("simple.foo"));
QVERIFY(available.contains("simple.foo.bar"));
QScriptValue extensionObject;
{
QVERIFY(eng.importExtension("simple").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 1);
QCOMPARE(eng.importedExtensions().at(0), QString::fromLatin1("simple"));
QVERIFY(eng.availableExtensions().contains("simple"));
QVERIFY(eng.globalObject().property("pluginKey").equals("simple"));
QVERIFY(eng.globalObject().property("package").isObject());
extensionObject = eng.globalObject().property("simple");
QVERIFY(extensionObject.isObject());
QVERIFY(extensionObject.equals(eng.globalObject().property("package")));
}
{
QVERIFY(eng.importExtension("simple.foo").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 2);
QCOMPARE(eng.importedExtensions().at(1), QString::fromLatin1("simple.foo"));
QVERIFY(eng.availableExtensions().contains("simple.foo"));
QVERIFY(eng.globalObject().property("pluginKey").equals("simple.foo"));
QVERIFY(eng.globalObject().property("package").isObject());
QVERIFY(!extensionObject.equals(eng.globalObject().property("package")));
QVERIFY(extensionObject.equals(eng.globalObject().property("simple")));
QVERIFY(extensionObject.property("foo").isObject());
QVERIFY(extensionObject.property("foo").equals(eng.globalObject().property("package")));
}
{
QVERIFY(eng.importExtension("simple.foo.bar").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 3);
QCOMPARE(eng.importedExtensions().at(2), QString::fromLatin1("simple.foo.bar"));
QVERIFY(eng.availableExtensions().contains("simple.foo.bar"));
QVERIFY(eng.globalObject().property("pluginKey").equals("simple.foo.bar"));
QVERIFY(eng.globalObject().property("package").isObject());
QVERIFY(!extensionObject.equals(eng.globalObject().property("package")));
QVERIFY(extensionObject.equals(eng.globalObject().property("simple")));
QVERIFY(extensionObject.property("foo").property("bar").isObject());
QVERIFY(extensionObject.property("foo").property("bar").equals(eng.globalObject().property("package")));
}
// Extensions can't be imported multiple times.
eng.globalObject().setProperty("pluginKey", QScriptValue());
QVERIFY(eng.importExtension("simple").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 3);
QVERIFY(!eng.globalObject().property("pluginKey").isValid());
QVERIFY(eng.importExtension("simple.foo").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 3);
QVERIFY(!eng.globalObject().property("pluginKey").isValid());
QVERIFY(eng.importExtension("simple.foo.bar").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 3);
QVERIFY(!eng.globalObject().property("pluginKey").isValid());
}