diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-04-14 01:31:05 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-04-14 01:31:05 (GMT) |
commit | 428317f83fd8b7a62244a446b76299de050d1325 (patch) | |
tree | a088685b37f99fb27a2fdcbdf32cd3db0fccdd75 /src/declarative/qml/qdeclarativeengine.cpp | |
parent | 65020d507a5b6a932034b9d6ee57fd765893f3ad (diff) | |
download | Qt-428317f83fd8b7a62244a446b76299de050d1325.zip Qt-428317f83fd8b7a62244a446b76299de050d1325.tar.gz Qt-428317f83fd8b7a62244a446b76299de050d1325.tar.bz2 |
Give better error messages on plugin load failures.
Fixes reverted commit e0dcdbd2984299665b9b784b201289219b9978d3.
Diffstat (limited to 'src/declarative/qml/qdeclarativeengine.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index f1adc16..e2f810e 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1486,13 +1486,17 @@ public: QSet<QString> qmlDirFilesForWhichPluginsHaveBeenLoaded; - QDeclarativeDirComponents importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine) { + bool importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine, QDeclarativeDirComponents* components, QString *errorString) { QFile file(absoluteFilePath); QString filecontent; if (file.open(QFile::ReadOnly)) { filecontent = QString::fromUtf8(file.readAll()); if (qmlImportTrace()) qDebug() << "QDeclarativeEngine::add: loaded" << absoluteFilePath; + } else { + if (errorString) + *errorString = QDeclarativeEngine::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath); + return false; } QDir dir = QFileInfo(file).dir(); @@ -1512,11 +1516,23 @@ public: plugin.name); if (!resolvedFilePath.isEmpty()) { - engine->importPlugin(resolvedFilePath, uri); + if (!engine->importPlugin(resolvedFilePath, uri, errorString)) { + if (errorString) + *errorString = QDeclarativeEngine::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri).arg(*errorString); + return false; + } + } else { + if (errorString) + *errorString = QDeclarativeEngine::tr("module \"%1\" plugin \"%2\" not found").arg(uri).arg(plugin.name); + return false; } } } - return qmldirParser.components(); + + if (components) + *components = qmldirParser.components(); + + return true; } QString resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine) @@ -1577,7 +1593,8 @@ public: url = QUrl::fromLocalFile(fi.absolutePath()).toString(); uri = resolvedUri(dir, engine); - qmldircomponents = importExtension(absoluteFilePath, uri, engine); + if (!importExtension(absoluteFilePath, uri, engine, &qmldircomponents, errorString)) + return false; break; } } @@ -1608,12 +1625,12 @@ public: return false; // local import dirs must exist } uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), engine); - qmldircomponents = importExtension(localFileOrQrc, - uri, - engine); - if (uri.endsWith(QLatin1Char('/'))) uri.chop(1); + if (QFile::exists(localFileOrQrc)) { + if (!importExtension(localFileOrQrc,uri,engine,&qmldircomponents,errorString)) + return false; + } } else { if (prefix.isEmpty()) { // directory must at least exist for valid import @@ -1927,7 +1944,7 @@ void QDeclarativeEngine::setPluginPathList(const QStringList &paths) Imports the plugin named \a filePath with the \a uri provided. Returns true if the plugin was successfully imported; otherwise returns false. */ -bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri) +bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri, QString *errorString) { if (qmlImportTrace()) qDebug() << "QDeclarativeEngine::importPlugin" << uri << "from" << filePath; @@ -1948,9 +1965,8 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur QPluginLoader loader(absoluteFilePath); if (!loader.load()) { - if (qmlImportTrace()) { - qDebug() << "QDeclarativeEngine::importPlugin: " << loader.errorString(); - } + if (errorString) + *errorString = loader.errorString(); return false; } @@ -1972,8 +1988,8 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur iface->initializeEngine(this, moduleId); } } else { - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::importPlugin: no DeclarativeExtensionInterface error"; + if (errorString) + *errorString = loader.errorString(); return false; } } |