summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <[email protected]>2024-01-25 13:35:28 +0100
committerTor Arne Vestbø <[email protected]>2024-01-25 18:37:47 +0100
commit3f2a9523a442e44ef52ebca30da9b5d3188df6bc (patch)
treec50a8569109465f0bf2d48afa23d3fb57bb6d80b
parent9932f2dd479baefb915ad841c95855d61b764ab6 (diff)
qWaitForWindowFocused: Pass timeout as QDeadlineTimer
We should avoid int-based timeouts nowadays, and prefer std::chrono, or for timeouts where Forever is a valid state, QDeadlineTimer. Discovered during API header review. Pick-to: 6.7 Change-Id: Ia56a67084c7a2f989951755fed5ffc161ed8f79e Reviewed-by: Marc Mutz <[email protected]>
-rw-r--r--src/gui/kernel/qtestsupport_gui.cpp4
-rw-r--r--src/gui/kernel/qtestsupport_gui.h2
-rw-r--r--src/widgets/kernel/qtestsupport_widgets.cpp8
-rw-r--r--src/widgets/kernel/qtestsupport_widgets.h2
4 files changed, 8 insertions, 8 deletions
diff --git a/src/gui/kernel/qtestsupport_gui.cpp b/src/gui/kernel/qtestsupport_gui.cpp
index b43f7ab163e..869eddce494 100644
--- a/src/gui/kernel/qtestsupport_gui.cpp
+++ b/src/gui/kernel/qtestsupport_gui.cpp
@@ -47,7 +47,7 @@ Q_GUI_EXPORT bool QTest::qWaitForWindowActive(QWindow *window, int timeout)
/*!
\since 6.7
- Returns \c true, if \a window is the focus window within \a timeout milliseconds. Otherwise returns \c false.
+ Returns \c true, if \a window is the focus window within \a timeout. Otherwise returns \c false.
The method is useful in tests that call QWindow::show() and rely on the window
having focus (for receiving keyboard events e.g.) before proceeding.
@@ -60,7 +60,7 @@ Q_GUI_EXPORT bool QTest::qWaitForWindowActive(QWindow *window, int timeout)
\sa qWaitForWindowExposed(), qWaitForWindowActive(), QGuiApplication::focusWindow()
*/
-Q_GUI_EXPORT bool QTest::qWaitForWindowFocused(QWindow *window, int timeout)
+Q_GUI_EXPORT bool QTest::qWaitForWindowFocused(QWindow *window, QDeadlineTimer timeout)
{
return QTest::qWaitFor([&]() { return qGuiApp->focusWindow() == window; }, timeout);
}
diff --git a/src/gui/kernel/qtestsupport_gui.h b/src/gui/kernel/qtestsupport_gui.h
index e676324bb0e..e5b2a884558 100644
--- a/src/gui/kernel/qtestsupport_gui.h
+++ b/src/gui/kernel/qtestsupport_gui.h
@@ -23,7 +23,7 @@ Q_GUI_EXPORT bool qt_handleTouchEventv2(QWindow *w, const QPointingDevice *devic
namespace QTest {
[[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout = 5000);
-[[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowFocused(QWindow *window, int timeout = 5000);
+[[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowFocused(QWindow *widget, QDeadlineTimer timeout = std::chrono::seconds{5});
[[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout = 5000);
Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType = QInputDevice::DeviceType::TouchScreen,
diff --git a/src/widgets/kernel/qtestsupport_widgets.cpp b/src/widgets/kernel/qtestsupport_widgets.cpp
index 226c56140d9..f7b25b6643b 100644
--- a/src/widgets/kernel/qtestsupport_widgets.cpp
+++ b/src/widgets/kernel/qtestsupport_widgets.cpp
@@ -16,8 +16,8 @@
QT_BEGIN_NAMESPACE
-template <typename FunctorWindowGetter, typename FunctorPredicate>
-static bool qWaitForWidgetWindow(FunctorWindowGetter windowGetter, FunctorPredicate predicate, int timeout)
+template <typename FunctorWindowGetter, typename FunctorPredicate, typename Timeout>
+static bool qWaitForWidgetWindow(FunctorWindowGetter windowGetter, FunctorPredicate predicate, Timeout timeout)
{
if (!windowGetter())
return false;
@@ -64,7 +64,7 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout)
/*!
\since 6.7
- Returns \c true, if \a widget is the focus window within \a timeout milliseconds. Otherwise returns \c false.
+ Returns \c true, if \a widget is the focus window within \a timeout. Otherwise returns \c false.
The method is useful in tests that call QWidget::show() and rely on the widget
having focus (for receiving keyboard events e.g.) before proceeding.
@@ -77,7 +77,7 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout)
\sa qWaitForWindowExposed(), qWaitForWindowActive(), QGuiApplication::focusWindow()
*/
-Q_WIDGETS_EXPORT bool QTest::qWaitForWindowFocused(QWidget *widget, int timeout)
+Q_WIDGETS_EXPORT bool QTest::qWaitForWindowFocused(QWidget *widget, QDeadlineTimer timeout)
{
return qWaitForWidgetWindow([&]() {
return widget->window()->windowHandle();
diff --git a/src/widgets/kernel/qtestsupport_widgets.h b/src/widgets/kernel/qtestsupport_widgets.h
index cb8ab21069a..b49e68db651 100644
--- a/src/widgets/kernel/qtestsupport_widgets.h
+++ b/src/widgets/kernel/qtestsupport_widgets.h
@@ -15,7 +15,7 @@ class QWidget;
namespace QTest {
[[nodiscard]] Q_WIDGETS_EXPORT bool qWaitForWindowActive(QWidget *widget, int timeout = 5000);
-[[nodiscard]] Q_WIDGETS_EXPORT bool qWaitForWindowFocused(QWidget *widget, int timeout = 5000);
+[[nodiscard]] Q_WIDGETS_EXPORT bool qWaitForWindowFocused(QWidget *widget, QDeadlineTimer timeout = std::chrono::seconds{5});
[[nodiscard]] Q_WIDGETS_EXPORT bool qWaitForWindowExposed(QWidget *widget, int timeout = 5000);
class Q_WIDGETS_EXPORT QTouchEventWidgetSequence : public QTouchEventSequence