From 0402743339cbf9efe0ea4ebbd36b27bbc7e9e7a6 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Thu, 13 Mar 2014 14:40:44 +0100 Subject: UI: fix a crash on shutdown Use a raw pointer instead of QScopedPointer for the UI components. Since the components are always parented to the view and deleted through the QObject cleanup mechanism, it was not correct to use QScopedPointer in the first place. Change-Id: I0c8fd9526e898439c52c6a6f538a66f8a1185ef9 Reviewed-by: Jocelyn Turcotte --- src/webengine/ui_delegates_manager.cpp | 20 ++++++++++++-------- src/webengine/ui_delegates_manager.h | 3 +-- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/webengine') diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp index 1402c7625..5fb5ef475 100644 --- a/src/webengine/ui_delegates_manager.cpp +++ b/src/webengine/ui_delegates_manager.cpp @@ -109,8 +109,12 @@ void NavigateMenuItem::onTriggered() m_adapter->load(m_targetUrl); } +#define COMPONENT_MEMBER_INIT(TYPE, COMPONENT) \ + , COMPONENT##Component(0) + UIDelegatesManager::UIDelegatesManager(QQuickWebEngineView *view) : m_view(view) + FOR_EACH_COMPONENT_TYPE(COMPONENT_MEMBER_INIT, NO_SEPARATOR) { } @@ -121,7 +125,7 @@ UIDelegatesManager::UIDelegatesManager(QQuickWebEngineView *view) bool UIDelegatesManager::ensureComponentLoaded(ComponentType type) { - QScopedPointer *component; + QQmlComponent **component; switch (type) { FOR_EACH_COMPONENT_TYPE(COMPONENT_MEMBER_CASE_STATEMENT, NO_SEPARATOR) default: @@ -130,7 +134,7 @@ bool UIDelegatesManager::ensureComponentLoaded(ComponentType type) } QString fileName(fileNameForComponent(type)); #ifndef UI_DELEGATES_DEBUG - if (!(*component).isNull()) + if (*component) return true; #else // Unconditionally reload the components each time. fprintf(stderr, "%s: %s\n", Q_FUNC_INFO, qPrintable(fileName)); @@ -145,7 +149,7 @@ bool UIDelegatesManager::ensureComponentLoaded(ComponentType type) absolutePath = fi.absoluteFilePath(); } // FIXME: handle async loading - (*component).reset(new QQmlComponent(engine, QUrl(absolutePath), QQmlComponent::PreferSynchronous, m_view)); + *component = (new QQmlComponent(engine, QUrl(absolutePath), QQmlComponent::PreferSynchronous, m_view)); if ((*component)->status() != QQmlComponent::Ready) { #ifdef UI_DELEGATES_DEBUG @@ -175,7 +179,7 @@ void UIDelegatesManager::addMenuItem(MenuItemHandler *menuItemHandler, const QSt Q_ASSERT(menuItemHandler); if (!ensureComponentLoaded(MenuItem)) return; - QObject *it = menuItemComponent->beginCreate(creationContextForComponent(menuItemComponent.data())); + QObject *it = menuItemComponent->beginCreate(creationContextForComponent(menuItemComponent)); QQmlProperty(it, QStringLiteral("text")).write(text); QQmlProperty(it, QStringLiteral("iconName")).write(iconName); @@ -199,7 +203,7 @@ void UIDelegatesManager::addMenuSeparator(QObject *menu) if (!ensureComponentLoaded(MenuSeparator)) return; - QQmlContext *itemContext = creationContextForComponent(menuSeparatorComponent.data()); + QQmlContext *itemContext = creationContextForComponent(menuSeparatorComponent); QObject *sep = menuSeparatorComponent->create(itemContext); sep->setParent(menu); @@ -213,7 +217,7 @@ QObject *UIDelegatesManager::addMenu(QObject *parentMenu, const QString &title, if (!ensureComponentLoaded(Menu)) return 0; - QQmlContext *context(creationContextForComponent(menuComponent.data())); + QQmlContext *context(creationContextForComponent(menuComponent)); QObject *menu = menuComponent->beginCreate(context); // Useful when not using Qt Quick Controls' Menu if (QQuickItem* item = qobject_cast(menu)) @@ -241,7 +245,7 @@ QObject *UIDelegatesManager::addMenu(QObject *parentMenu, const QString &title, #define ASSIGN_DIALOG_COMPONENT_DATA_CASE_STATEMENT(TYPE, COMPONENT) \ case TYPE:\ - dialogComponent = COMPONENT##Component.data(); \ + dialogComponent = COMPONENT##Component; \ break; @@ -360,7 +364,7 @@ void UIDelegatesManager::showFilePicker(WebContentsAdapterClient::FileChooserMod if (!ensureComponentLoaded(FilePicker)) return; - QQmlContext *context(creationContextForComponent(filePickerComponent.data())); + QQmlContext *context(creationContextForComponent(filePickerComponent)); QObject *filePicker = filePickerComponent->beginCreate(context); if (QQuickItem* item = qobject_cast(filePicker)) item->setParentItem(m_view); diff --git a/src/webengine/ui_delegates_manager.h b/src/webengine/ui_delegates_manager.h index a6d15a530..125cacff4 100644 --- a/src/webengine/ui_delegates_manager.h +++ b/src/webengine/ui_delegates_manager.h @@ -49,7 +49,6 @@ #include #include #include -#include #include #include @@ -67,7 +66,7 @@ #define ENUM_DECLARATION(TYPE, COMPONENT) \ TYPE #define MEMBER_DECLARATION(TYPE, COMPONENT) \ - QScopedPointer COMPONENT##Component + QQmlComponent *COMPONENT##Component class JavaScriptDialogController; QT_BEGIN_NAMESPACE -- cgit v1.2.3