本文整理汇总了C++中QScriptEngine::availableExtensions方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEngine::availableExtensions方法的具体用法?C++ QScriptEngine::availableExtensions怎么用?C++ QScriptEngine::availableExtensions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptEngine
的用法示例。
在下文中一共展示了QScriptEngine::availableExtensions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
int main(int argc, char *argv[])
{
QString databaseName(":memory:");
/* Create application */
QCoreApplication app(argc, argv);
/* Parse command line arguments */
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-h"))
{
usage();
return EXIT_SUCCESS;
} else if (!strcmp(argv[i], "-d")) {
if (i == argc - 1 || !strlen(argv[i+1]) || argv[i+1][0] == '-')
{
fprintf(stderr, "Option -d requires an argument\n");
usage();
return EXIT_FAILURE;
}
databaseName = QString::fromLocal8Bit(argv[++i]);
} else if (!strcmp(argv[i], "-p")) {
if (i == argc - 1 || !strlen(argv[i+1]) || argv[i+1][0] == '-')
{
fprintf(stderr, "Option -p requires an argument\n");
usage();
return EXIT_FAILURE;
}
app.setLibraryPaths(app.libraryPaths() << QString::fromLocal8Bit(argv[++i]));
}
}
/* Open database */
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(databaseName);
if (!db.open())
{
fprintf(stderr, "Could not access database '%s'\n", databaseName.toLocal8Bit().constData());
return EXIT_FAILURE;
}
QDjango::setDatabase(db);
/* Run interactive shell */
QScriptEngine *engine = new QScriptEngine();
QDjangoScript::registerWhere(engine);
QDjangoScript::registerModel<User>(engine);
QDjangoScript::registerModel<Group>(engine);
QDjangoScript::registerModel<Message>(engine);
qDebug() << "Available extensions: " << engine->availableExtensions();
interactive(engine);
return EXIT_SUCCESS;
}
示例3: main
int main(int argc, char **argv)
{
QCoreApplication app( argc, argv );
QStringList allowedBindings;
allowedBindings << "qt.core" << "qt.gui" << "qt.sql" << "qt.xml" << "qt.uitools" << "qt.network" << "qt.webkit";
QScriptEngine engine;
foreach( QString binding, allowedBindings )
{
QScriptValue error = engine.importExtension( binding );
if( error.isUndefined() )
{ // undefined indiciates success
continue;
}
qDebug() << "Extension" << binding << "not found:" << error.toString();
qDebug() << "Available extensions:" << engine.availableExtensions();
return FAIL;
}
示例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());
}