From 705f53e985104dcd52d684228cc923e9dbd9938b Mon Sep 17 00:00:00 2001 From: Pierre Lamot Date: Mon, 27 Feb 2023 11:18:24 +0100 Subject: [PATCH] qml: fix race condition while initializing FlickableScrollHandler fix: #27890 --- modules/gui/qt/util/flickable_scroll_handler.cpp | 8 +++++--- modules/gui/qt/util/flickable_scroll_handler.hpp | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/gui/qt/util/flickable_scroll_handler.cpp b/modules/gui/qt/util/flickable_scroll_handler.cpp index 451e9d9ad2..f39061bbb6 100644 --- a/modules/gui/qt/util/flickable_scroll_handler.cpp +++ b/modules/gui/qt/util/flickable_scroll_handler.cpp @@ -34,8 +34,6 @@ FlickableScrollHandler::FlickableScrollHandler(QObject *parent) }); setScaleFactor(1.0); - - QMetaObject::invokeMethod(this, &FlickableScrollHandler::init, Qt::QueuedConnection); } FlickableScrollHandler::~FlickableScrollHandler() @@ -43,7 +41,11 @@ FlickableScrollHandler::~FlickableScrollHandler() detach(); } -void FlickableScrollHandler::init() +void FlickableScrollHandler::classBegin() +{ +} + +void FlickableScrollHandler::componentComplete() { assert(parent()); diff --git a/modules/gui/qt/util/flickable_scroll_handler.hpp b/modules/gui/qt/util/flickable_scroll_handler.hpp index b5a82887ff..8b68bb99b2 100644 --- a/modules/gui/qt/util/flickable_scroll_handler.hpp +++ b/modules/gui/qt/util/flickable_scroll_handler.hpp @@ -22,8 +22,9 @@ #include #include #include +#include -class FlickableScrollHandler : public QObject +class FlickableScrollHandler : public QObject, public QQmlParserStatus { Q_OBJECT @@ -35,6 +36,8 @@ class FlickableScrollHandler : public QObject Q_PROPERTY(bool fallbackScroll MEMBER m_fallbackScroll NOTIFY fallbackScrollChanged FINAL) Q_PROPERTY(bool handleOnlyPixelDelta MEMBER m_handleOnlyPixelDelta NOTIFY handleOnlyPixelDeltaChanged FINAL) + Q_INTERFACES(QQmlParserStatus) + public: explicit FlickableScrollHandler(QObject *parent = nullptr); ~FlickableScrollHandler(); @@ -46,6 +49,9 @@ public: void setScaleFactor(qreal newScaleFactor); void setEnabled(bool newEnabled); + void classBegin() override; + void componentComplete() override; + signals: void initialized(); @@ -57,8 +63,6 @@ signals: void handleOnlyPixelDeltaChanged(); private slots: - void init(); - void adjustScrollBarV(); void adjustScrollBarH();