summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-02-02 10:25:37 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2018-02-07 10:41:05 +0000
commit9b340999c4cb9db1975c4b63f3388899d9023944 (patch)
treea95ae295da4be657789b8a7d237db459f49d4938
parent4459886e3f949821425dd5fd9fc9da0416d0ffc9 (diff)
downloadqtquickcontrols-9b340999c4cb9db1975c4b63f3388899d9023944.tar.gz
Fix memory leak in QQC1
When repeatedly creating a QQuickView, loading a QML file that imports QQC1 and deleting the view again, we would leak memory that was allocated as a consequence of QML type registration in initializeEngine() callbacks that were called on every iteration. After the limitation of namespacing in the registerTypes() callback of QML module plugins has been lifted, we can move the type registrations into registerTypes() where they belong and which is called only once. Change-Id: I1d21b18dd060e169a1ee1095f5c5af7341443492 Reviewed-by: J-P Nurmi <jpnurmi@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Michael Winkelmann <michael.winkelmann@qt.io>
-rw-r--r--src/controls/plugin.cpp13
-rw-r--r--src/extras/plugin.cpp10
-rw-r--r--src/extras/plugin.h1
3 files changed, 8 insertions, 16 deletions
diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp
index f78098ec..4eb6c466 100644
--- a/src/controls/plugin.cpp
+++ b/src/controls/plugin.cpp
@@ -149,11 +149,6 @@ void QtQuickControls1Plugin::registerTypes(const char *uri)
const QString filesLocation = fileLocation();
for (int i = 0; i < int(sizeof(qmldir)/sizeof(qmldir[0])); i++)
qmlRegisterType(QUrl(filesLocation + "/" + qmldir[i].type + ".qml"), uri, qmldir[i].major, qmldir[i].minor, qmldir[i].type);
-}
-
-void QtQuickControls1Plugin::initializeEngine(QQmlEngine *engine, const char *uri)
-{
- Q_UNUSED(uri);
// Register private API. Note that to use these types outside of the
// Qt Quick Controls module, both the public and private imports must be used.
@@ -185,6 +180,14 @@ void QtQuickControls1Plugin::initializeEngine(QQmlEngine *engine, const char *ur
#ifdef QT_WIDGETS_LIB
qmlRegisterType<QQuickStyleItem1>(private_uri, 1, 0, "StyleItem");
+#endif
+}
+
+void QtQuickControls1Plugin::initializeEngine(QQmlEngine *engine, const char *uri)
+{
+ Q_UNUSED(uri);
+
+#ifdef QT_WIDGETS_LIB
engine->addImageProvider("__tablerow", new QQuickTableRowImageProvider1);
#endif
engine->addImageProvider("desktoptheme", new QQuickDesktopIconProvider1);
diff --git a/src/extras/plugin.cpp b/src/extras/plugin.cpp
index 5133a4ac..68d6ca16 100644
--- a/src/extras/plugin.cpp
+++ b/src/extras/plugin.cpp
@@ -99,22 +99,12 @@ void QtQuickExtrasPlugin::registerTypes(const char *uri)
#if QT_CONFIG(picture)
qmlRegisterType<QQuickPicture>(uri, 1, 4, "Picture");
#endif
-}
-void QtQuickExtrasPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
-{
- Q_UNUSED(uri);
- Q_UNUSED(engine);
qmlRegisterType<QQuickMouseThief>("QtQuick.Extras.Private.CppUtils", 1, 0, "MouseThief");
qmlRegisterType<QQuickCircularProgressBar>("QtQuick.Extras.Private.CppUtils", 1, 1, "CircularProgressBar");
qmlRegisterType<QQuickFlatProgressBar>("QtQuick.Extras.Private.CppUtils", 1, 1, "FlatProgressBar");
qmlRegisterSingletonType<QQuickMathUtils>("QtQuick.Extras.Private.CppUtils", 1, 0, "MathUtils", registerMathUtilsSingleton);
-#ifndef QT_STATIC
- const QString prefix = baseUrl().toString();
-#else
- const QString prefix = "qrc:/qt-project.org/imports/QtQuick/Extras";
-#endif
const char *private_uri = "QtQuick.Extras.Private";
qmlRegisterType(QUrl(prefix + "/Private/CircularButton.qml"), private_uri, 1, 0, "CircularButton");
qmlRegisterType(QUrl(prefix + "/Private/CircularButtonStyleHelper.qml"), private_uri, 1, 0, "CircularButtonStyleHelper");
diff --git a/src/extras/plugin.h b/src/extras/plugin.h
index 05855f49..5f0a380e 100644
--- a/src/extras/plugin.h
+++ b/src/extras/plugin.h
@@ -54,7 +54,6 @@ public:
explicit QtQuickExtrasPlugin(QObject *parent = 0);
void registerTypes(const char *uri);
- void initializeEngine(QQmlEngine *engine, const char *uri);
};
QT_END_NAMESPACE