From 560f10aee4f3294b65f58a9579b0e76009c1de4a Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Tue, 20 May 2014 13:51:42 +0200 Subject: 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 --- src/webengine/ui_delegates_manager.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src') 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 -- cgit v1.2.3