diff options
authorAndreas Hartmetz <andreas@ixgreen.de>2021-03-05 12:41:06 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-11 09:08:57 +0000
commitf58bbc4622048b87549381796be4226f45ffaa69 (patch)
parentd7f4a51d58d7ff9e8ac5c471476ca1608d48d055 (diff)
QQuickWindow: don't leak old screenChanged connections
Connections could accumulate. Because the newest one was invoked last due to how signal-slot invocations are ordered, rendering was correct, but the stale connections caused unnecessary updates (and wasted a small amount of memory). This comes from a misunderstanding I had at the time about how QMetaObject::Connection works. Destroying or overwriting one does not affect the actual connection. While at it, also modernize the connect(). Change-Id: Idde81bdbff8947ed517bf2740d623a395c0acb74 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 9f8292d48913c5bc50377749c2b3e030cf16d703) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
1 files changed, 3 insertions, 4 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 2b39153723..f30736d00b 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -466,15 +466,14 @@ void QQuickWindow::physicalDpiChanged()
void QQuickWindow::handleScreenChanged(QScreen *screen)
+ disconnect(d->physicalDpiChangedConnection);
if (screen) {
// When physical DPI changes on the same screen, either the resolution or the device pixel
// ratio changed. We must check what it is. Device pixel ratio does not have its own
// ...Changed() signal.
- d->physicalDpiChangedConnection = connect(screen, SIGNAL(physicalDotsPerInchChanged(qreal)),
- this, SLOT(physicalDpiChanged()));
- } else {
- disconnect(d->physicalDpiChangedConnection);
+ d->physicalDpiChangedConnection = connect(screen, &QScreen::physicalDotsPerInchChanged,
+ this, &QQuickWindow::physicalDpiChanged);