本文整理汇总了C++中QScriptEngine::importedExtensions方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEngine::importedExtensions方法的具体用法?C++ QScriptEngine::importedExtensions怎么用?C++ QScriptEngine::importedExtensions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptEngine
的用法示例。
在下文中一共展示了QScriptEngine::importedExtensions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: importStaticPlugin
void tst_QScriptExtensionPlugin::importStaticPlugin()
{
Q_INIT_RESOURCE(staticplugin);
QScriptEngine eng;
QVERIFY(eng.availableExtensions().contains("static"));
QVERIFY(eng.importExtension("static").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 1);
QCOMPARE(eng.importedExtensions().at(0), QString::fromLatin1("static"));
QVERIFY(eng.availableExtensions().contains("static"));
QVERIFY(eng.globalObject().property("pluginKey").equals("static"));
// Verify that :/qtscriptextension/static/__init__.js was evaluated.
QVERIFY(eng.evaluate("spy").isObject());
QVERIFY(eng.evaluate("spy.extension").equals("static"));
QVERIFY(eng.evaluate("spy.setupPackage").isFunction());
QVERIFY(eng.evaluate("spy.postInit").isUndefined());
QVERIFY(eng.evaluate("postInitWasCalled").isBool());
QVERIFY(eng.evaluate("postInitWasCalled").toBool());
// Extensions can't be imported multiple times.
eng.globalObject().setProperty("pluginKey", QScriptValue());
QVERIFY(eng.importExtension("static").isUndefined());
QCOMPARE(eng.importedExtensions().size(), 1);
QVERIFY(!eng.globalObject().property("pluginKey").isValid());
}
示例2: 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());
}