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. Change-Id: Ia56a67084c7a2f989951755fed5ffc161ed8f79e Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit 3f2a9523a442e44ef52ebca30da9b5d3188df6bc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
e15dd3f169
commit
dbda879127
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user