diff options
author | Pierre Rossi <pierre.rossi@digia.com> | 2014-05-20 13:51:42 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-20 15:02:03 +0200 |
commit | 560f10aee4f3294b65f58a9579b0e76009c1de4a (patch) | |
tree | 3f107d39960169c0567288d189b0f8182e5e54ff | |
parent | b9dc6fc3df7d66ca519b4b12b31f0b68297da84c (diff) | |
download | qtwebengine-560f10aee4f3294b65f58a9579b0e76009c1de4a.tar.gz |
Fix a crash when running witout UI delegates.
Lookup the correct UIDelegates import path once lazily, and reuse
this information. If there is none, then we don't expect any UI
delegation to work, but it should not crash.
Change-Id: I73be7273d83b8d89b74641dc550341cf2b7eb602
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
-rw-r--r-- | src/webengine/ui_delegates_manager.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp index 919b3f622..969a46758 100644 --- a/src/webengine/ui_delegates_manager.cpp +++ b/src/webengine/ui_delegates_manager.cpp @@ -78,6 +78,22 @@ static QString fileNameForComponent(UIDelegatesManager::ComponentType type) return QString(); } +static QString getUIDelegatesImportDir(QQmlEngine *engine) { + static QString importDir; + static bool initialized = false; + if (initialized) + return importDir; + Q_FOREACH (const QString &path, engine->importPathList()) { + QFileInfo fi(path % QStringLiteral("/QtWebEngine/UIDelegates/")); + if (fi.exists()) { + importDir = fi.absolutePath(); + break; + } + } + initialized = true; + return importDir; +} + MenuItemHandler::MenuItemHandler(QObject *parent) : QObject(parent) { @@ -125,6 +141,9 @@ UIDelegatesManager::UIDelegatesManager(QQuickWebEngineView *view) bool UIDelegatesManager::ensureComponentLoaded(ComponentType type) { + QQmlEngine* engine = qmlEngine(m_view); + if (getUIDelegatesImportDir(engine).isNull()) + return false; QQmlComponent **component; switch (type) { FOR_EACH_COMPONENT_TYPE(COMPONENT_MEMBER_CASE_STATEMENT, NO_SEPARATOR) @@ -139,17 +158,13 @@ bool UIDelegatesManager::ensureComponentLoaded(ComponentType type) #else // Unconditionally reload the components each time. fprintf(stderr, "%s: %s\n", Q_FUNC_INFO, qPrintable(fileName)); #endif - QQmlEngine* engine = qmlEngine(m_view); if (!engine) return false; - QString absolutePath; - Q_FOREACH (const QString &path, engine->importPathList()) { - QFileInfo fi(path % QStringLiteral("/QtWebEngine/UIDelegates/") % fileName); - if (fi.exists()) - absolutePath = fi.absoluteFilePath(); - } + QFileInfo fi(getUIDelegatesImportDir(engine) % '/' % fileName); + if (!fi.exists()) + return false; // FIXME: handle async loading - *component = (new QQmlComponent(engine, QUrl(absolutePath), QQmlComponent::PreferSynchronous, m_view)); + *component = (new QQmlComponent(engine, QUrl(fi.absoluteFilePath()), QQmlComponent::PreferSynchronous, m_view)); if ((*component)->status() != QQmlComponent::Ready) { #ifdef UI_DELEGATES_DEBUG |