summaryrefslogtreecommitdiffstats
path: root/src/webengine/ui_delegates_manager.cpp
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2016-06-09 16:02:10 +0200
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-06-13 09:59:49 +0000
commit9764fa47ee9b4f8ccf1c7cb0dc073bdc8a4f9c86 (patch)
tree47a0490a8eeed9f3a02e151ddbdbb846f72096e1 /src/webengine/ui_delegates_manager.cpp
parentbcc580aaa9ae5121db701d2e5ad03ef312f4e4ab (diff)
Fix memory leak of qml menu
Current qml menu implementation uses always WebEngineView as the parent of the menu. However menu can be triggered several times during WebEngineView lifetime, each time creating new menu component. Use onDone menu signal instead to delete menu. Change-Id: I1a6064451e95453268a2cd46899e297e769dc1f1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/webengine/ui_delegates_manager.cpp')
-rw-r--r--src/webengine/ui_delegates_manager.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp
index 16554da68..88c4b7c19 100644
--- a/src/webengine/ui_delegates_manager.cpp
+++ b/src/webengine/ui_delegates_manager.cpp
@@ -204,7 +204,7 @@ void UIDelegatesManager::addMenuSeparator(QObject *menu)
QObject *UIDelegatesManager::addMenu(QObject *parentMenu, const QString &title, const QPoint& pos)
{
-
+ Q_ASSERT(parentMenu);
if (!ensureComponentLoaded(Menu))
return 0;
QQmlContext *context = qmlContext(m_view);
@@ -217,18 +217,18 @@ QObject *UIDelegatesManager::addMenu(QObject *parentMenu, const QString &title,
QQmlProperty(menu, QStringLiteral("title")).write(title);
if (!pos.isNull())
QQmlProperty(menu, QStringLiteral("pos")).write(pos);
- if (!parentMenu) {
- QQmlProperty doneSignal(menu, QStringLiteral("onDone"));
- static int deleteLaterIndex = menu->metaObject()->indexOfSlot("deleteLater()");
- if (doneSignal.isSignalProperty())
- QObject::connect(menu, doneSignal.method(), menu, menu->metaObject()->method(deleteLaterIndex));
- } else {
- menu->setParent(parentMenu);
- QQmlListReference entries(parentMenu, defaultPropertyName(parentMenu), qmlEngine(m_view));
- if (entries.isValid())
- entries.append(menu);
- }
+ menu->setParent(parentMenu);
+
+ QQmlProperty doneSignal(menu, QStringLiteral("onDone"));
+ static int deleteLaterIndex = menu->metaObject()->indexOfSlot("deleteLater()");
+ CHECK_QML_SIGNAL_PROPERTY(doneSignal, menuComponent->url());
+ QObject::connect(menu, doneSignal.method(), menu, menu->metaObject()->method(deleteLaterIndex));
+
+ QQmlListReference entries(parentMenu, defaultPropertyName(parentMenu), qmlEngine(m_view));
+ if (entries.isValid())
+ entries.append(menu);
+
menuComponent->completeCreate();
return menu;
}