summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-02-25 16:09:46 (GMT)
committerRoberto Raggi <roberto.raggi@nokia.com>2010-02-25 16:09:46 (GMT)
commit3752d188c46c6eed5d190900fe6654642b3b8c63 (patch)
tree342157571c7b622a1f6a9928e38a81bdfec2fb65
parent20b761aeffdc6c1ad3eff2098d9ecd3f3a42bf40 (diff)
downloadQt-3752d188c46c6eed5d190900fe6654642b3b8c63.zip
Qt-3752d188c46c6eed5d190900fe6654642b3b8c63.tar.gz
Qt-3752d188c46c6eed5d190900fe6654642b3b8c63.tar.bz2
Protect against double initialization.
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp24
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h2
2 files changed, 20 insertions, 6 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 717857b..af75e98 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -336,6 +336,7 @@ void QDeclarativeEnginePrivate::clear(SimpleList<QDeclarativeParserStatus> &pss)
}
Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer);
+Q_GLOBAL_STATIC(QSet<QString>, qmlEnginePluginsWithRegisteredTypes);
void QDeclarativeEnginePrivate::init()
{
@@ -1621,19 +1622,32 @@ void QDeclarativeEngine::addImportPath(const QString& path)
*/
bool QDeclarativeEngine::importExtension(const QString &fileName, const QString &uri)
{
- QPluginLoader loader(fileName);
+ QFileInfo fileInfo(fileName);
+ const QString absoluteFilePath = fileInfo.absoluteFilePath();
+ QPluginLoader loader(absoluteFilePath);
if (QDeclarativeExtensionInterface *iface = qobject_cast<QDeclarativeExtensionInterface *>(loader.instance())) {
const QByteArray bytes = uri.toUtf8();
const char *moduleId = bytes.constData();
- QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this);
- if (! d->importedPlugins.contains(fileName)) {
- d->importedPlugins.insert(fileName);
+ // ### this code should probably be protected with a mutex.
+ if (! qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath)) {
+ // types should only be registered once (they're global).
+
+ qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath);
iface->registerTypes(moduleId);
}
- iface->initializeEngine(this, moduleId);
+ QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this);
+
+ if (! d->initializedPlugins.contains(absoluteFilePath)) {
+ // things on the engine (eg. adding new global objects) have to be done for every engine.
+
+ // protect against double initialization
+ d->initializedPlugins.insert(absoluteFilePath);
+ iface->initializeEngine(this, moduleId);
+ }
+
return true;
}
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 6ef2f93..0359f98 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -267,7 +267,7 @@ public:
QStringList environmentImportPath;
- QSet<QString> importedPlugins;
+ QSet<QString> initializedPlugins;
QString resolvePlugin(const QDir &dir, const QString &baseName,
const QStringList &suffixes,