From 924b2d5d47a33d11999a8edbfe6960e9593038ec Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 6 Jan 2022 17:12:36 +0100 Subject: Don't crash when pasting text into TextArea If QQuickTextAreaPrivate::ensureCursorVisible() calls QQuickFlickable::setContentY() while the Flickable does not yet know the extents of its new content, it caused a crash when QQuickScrollBarPrivate::visualArea() called qBound(0, 1, -something). We need to wait until Flickable knows it can scroll that far. It turns out ensureCursorVisible() is called several times anyway, so it's OK to skip the calls that would ask the Flickable to scroll out-of-bounds. Pick-to: 6.3 Task-number: QTBUG-99582 Change-Id: Ifb374a81591df49d3c571f55cb3076a78a808918 Reviewed-by: Mitch Curtis --- src/qmltest/quicktestutil.cpp | 13 +++++++++++++ src/qmltest/quicktestutil_p.h | 2 ++ 2 files changed, 15 insertions(+) (limited to 'src/qmltest') diff --git a/src/qmltest/quicktestutil.cpp b/src/qmltest/quicktestutil.cpp index 994c66845b..25863c3842 100644 --- a/src/qmltest/quicktestutil.cpp +++ b/src/qmltest/quicktestutil.cpp @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -62,6 +63,18 @@ int QuickTestUtil::dragThreshold() const return QGuiApplication::styleHints()->startDragDistance(); } +void QuickTestUtil::populateClipboardText(int lineCount) +{ +#if QT_CONFIG(clipboard) + QString fmt(u"%1 bottles of beer on the wall, %1 bottles of beer; " + "take one down, pass it around, %2 bottles of beer on the wall."_qs); + QStringList lines; + for (int i = lineCount; i > 0; --i) + lines << fmt.arg(i).arg(i - 1); + QGuiApplication::clipboard()->setText(lines.join(u'\n')); +#endif +} + QJSValue QuickTestUtil::typeName(const QVariant &v) const { QString name = QString::fromUtf8(v.typeName()); diff --git a/src/qmltest/quicktestutil_p.h b/src/qmltest/quicktestutil_p.h index 1cf2a6f356..fae904b84c 100644 --- a/src/qmltest/quicktestutil_p.h +++ b/src/qmltest/quicktestutil_p.h @@ -73,6 +73,8 @@ public: bool printAvailableFunctions() const; int dragThreshold() const; + Q_INVOKABLE void populateClipboardText(int lineCount); + Q_SIGNALS: void printAvailableFunctionsChanged(); void dragThresholdChanged(); -- cgit v1.2.3