diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qtestsupport_core.cpp | 36 | ||||
-rw-r--r-- | src/corelib/kernel/qtestsupport_core.h | 1 | ||||
-rw-r--r-- | src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp | 5 |
3 files changed, 32 insertions, 10 deletions
diff --git a/src/corelib/kernel/qtestsupport_core.cpp b/src/corelib/kernel/qtestsupport_core.cpp index bc461114d89..a6221444180 100644 --- a/src/corelib/kernel/qtestsupport_core.cpp +++ b/src/corelib/kernel/qtestsupport_core.cpp @@ -5,15 +5,35 @@ #include <thread> +using namespace std::chrono_literals; + QT_BEGIN_NAMESPACE /*! - Sleeps for \a ms milliseconds, blocking execution of the - test. qSleep() will not do any event processing and leave your test - unresponsive. Network communication might time out while - sleeping. Use \l {QTest::qWait()} to do non-blocking sleeping. + \overload + + Sleeps for \a ms milliseconds, blocking execution of the test. + + Equivalent to calling: + \code + QTest::qSleep(std::chrono::milliseconds{ms}); + \endcode +*/ +void QTest::qSleep(int ms) +{ + QTest::qSleep(std::chrono::milliseconds{ms}); +} + +/*! + \since 6.7 + + Sleeps for \a msecs, blocking execution of the test. + + This method will not do any event processing and will leave your test + unresponsive. Network communication might time out while sleeping. + Use \l {QTest::qWait()} to do non-blocking sleeping. - \a ms must be greater than 0. + \a msecs must be greater than 0ms. \note Starting from Qt 6.7, this function is implemented using \c {std::this_thread::sleep_for}, so the accuracy of time spent depends @@ -26,10 +46,10 @@ QT_BEGIN_NAMESPACE \sa {QTest::qWait()} */ -Q_CORE_EXPORT void QTest::qSleep(int ms) +void QTest::qSleep(std::chrono::milliseconds msecs) { - Q_ASSERT(ms > 0); - std::this_thread::sleep_for(std::chrono::milliseconds{ms}); + Q_ASSERT(msecs > 0ms); + std::this_thread::sleep_for(msecs); } /*! \fn template <typename Functor> bool QTest::qWaitFor(Functor predicate, int timeout) diff --git a/src/corelib/kernel/qtestsupport_core.h b/src/corelib/kernel/qtestsupport_core.h index c9505196a91..f3aa2299104 100644 --- a/src/corelib/kernel/qtestsupport_core.h +++ b/src/corelib/kernel/qtestsupport_core.h @@ -13,6 +13,7 @@ QT_BEGIN_NAMESPACE namespace QTest { Q_CORE_EXPORT void qSleep(int ms); +Q_CORE_EXPORT void qSleep(std::chrono::milliseconds msecs); template <typename Functor> [[nodiscard]] static bool qWaitFor(Functor predicate, int timeout = 5000) diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp index 532b26b4f18..4716d06e55c 100644 --- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp +++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp @@ -170,10 +170,11 @@ void MyTestClass::cleanup() } //! [22] -void mySleep() +void quarterSecondSleep() { //! [23] -QTest::qSleep(250); +using namespace std::chrono_literals; +QTest::qSleep(250ms); //! [23] } |