Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQuickTest Namespace Reference

Functions

Q_QMLTEST_EXPORT bool qIsPolishScheduled (const QQuickItem *item)
 
Q_QMLTEST_EXPORT bool qIsPolishScheduled (const QQuickWindow *window)
 
Q_QMLTEST_EXPORT bool qWaitForPolish (const QQuickItem *item, int timeout=defaultTimeout)
 
Q_QMLTEST_EXPORT bool qWaitForPolish (const QQuickWindow *window, int timeout=defaultTimeout)
 
bool initView (QQuickView &view, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage)
 
bool showView (QQuickView &view, const QUrl &url)
 
void pointerPress (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
 
void pointerMove (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p)
 
void pointerRelease (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
 

Variables

static const int defaultTimeout = 5000
 
static Qt::MouseButton pressedTabletButton = Qt::NoButton
 
static Qt::KeyboardModifiers pressedTabletModifiers = Qt::NoModifier
 

Function Documentation

◆ initView()

bool QQuickTest::initView ( QQuickView & view,
const QUrl & url,
bool moveMouseOut,
QByteArray * errorMessage )

Initialize view, set url, center in available geometry, move mouse away if desired. If errorMessage is given, QQuickView::errors() will be concatenated into it; otherwise, the QWARN messages are generally enough to debug the test.

Returns false if the view fails to load the QML. That should be fatal in most tests, so normally the return value should be checked with QVERIFY.

Definition at line 469 of file viewtestutils.cpp.

References QRect::center(), errorMessage(), QQuickView::errors(), QWindow::height, initView(), QQuickView::Loading, Q_UNUSED, QTest::qWait(), QQuickView::Ready, QWindow::setHeight(), QCursor::setPos(), QQuickView::setSource(), QWindow::setWidth(), QQuickView::status, url, view, and QWindow::width.

Referenced by initView(), and showView().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pointerMove()

void QQuickTest::pointerMove ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & p )

Definition at line 553 of file viewtestutils.cpp.

References QInputDevice::Airbrush, QTest::defaultMouseDelay(), QQuickTouchUtils::flush(), QWindowSystemInterface::handleTabletEvent(), QTest::lastMouseTimestamp, QInputDevice::Mouse, QTest::mouseMove(), QTest::QTouchEventSequence::move(), pointerMove(), pressedTabletButton, pressedTabletModifiers, QInputDevice::Puck, qWarning, QInputDevice::Stylus, QTest::touchEvent(), QInputDevice::TouchPad, QInputDevice::TouchScreen, QInputDevice::type, and window().

Referenced by QQuickVisualTestUtils::PointLerper::move(), and pointerMove().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pointerPress()

void QQuickTest::pointerPress ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & p,
Qt::MouseButton button,
Qt::KeyboardModifiers modifiers )

Definition at line 526 of file viewtestutils.cpp.

References QInputDevice::Airbrush, button, QTest::defaultMouseDelay(), QQuickTouchUtils::flush(), QWindowSystemInterface::handleTabletEvent(), QTest::lastMouseTimestamp, QInputDevice::Mouse, QTest::mousePress(), pointerPress(), QTest::QTouchEventSequence::press(), pressedTabletButton, pressedTabletModifiers, QInputDevice::Puck, qWarning, QInputDevice::Stylus, QTest::touchEvent(), QInputDevice::TouchPad, QInputDevice::TouchScreen, QInputDevice::type, and window().

Referenced by pointerPress().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pointerRelease()

void QQuickTest::pointerRelease ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & p,
Qt::MouseButton button,
Qt::KeyboardModifiers modifiers )

Definition at line 577 of file viewtestutils.cpp.

References QInputDevice::Airbrush, button, QTest::defaultMouseDelay(), QQuickTouchUtils::flush(), QWindowSystemInterface::handleTabletEvent(), QTest::lastMouseTimestamp, QInputDevice::Mouse, QTest::mouseRelease(), Qt::NoButton, pointerRelease(), QInputDevice::Puck, qWarning, QTest::QTouchEventSequence::release(), QInputDevice::Stylus, QTest::touchEvent(), QInputDevice::TouchPad, QInputDevice::TouchScreen, QInputDevice::type, and window().

Referenced by pointerRelease().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qIsPolishScheduled() [1/2]

QT_BEGIN_NAMESPACE bool QQuickTest::qIsPolishScheduled ( const QQuickItem * item)
Since
5.13

Returns true if \l {QQuickItem::}{updatePolish()} has not been called on item since the last call to \l {QQuickItem::}{polish()}, otherwise returns false.

When assigning values to properties in QML, any layouting the item must do as a result of the assignment might not take effect immediately, but can instead be postponed until the item is polished. For these cases, you can use this function to ensure that the item has been polished before the execution of the test continues. For example:

QVERIFY(QQuickTest::qWaitForItemPolished(item));
Q_QMLTEST_EXPORT bool qIsPolishScheduled(const QQuickItem *item)
Definition quicktest.cpp:76
#define QVERIFY(statement)
Definition qtestcase.h:58
QGraphicsItem * item

Without the call to qIsPolishScheduled() above, the call to qWaitForItemPolished() might see that no polish was scheduled and therefore pass instantly, assuming that the item had already been polished. This function makes it obvious why an item wasn't polished and allows tests to fail early under such circumstances.

The QML equivalent of this function is \l {TestCase::}{isPolishScheduled()}.

See also
QQuickItem::polish(), QQuickItem::updatePolish()

Definition at line 76 of file quicktest.cpp.

References QQuickItemPrivate::get(), and item.

+ Here is the call graph for this function:

◆ qIsPolishScheduled() [2/2]

bool QQuickTest::qIsPolishScheduled ( const QQuickWindow * window)

Definition at line 104 of file quicktest.cpp.

References QQuickWindowPrivate::get(), and window().

+ Here is the call graph for this function:

◆ qWaitForPolish() [1/2]

bool QQuickTest::qWaitForPolish ( const QQuickItem * item,
int timeout = defaultTimeout )
Since
6.4

Waits for timeout milliseconds or until \l {QQuickItem::}{updatePolish()} has been called on item.

Returns true if updatePolish() was called on item within timeout milliseconds, otherwise returns false.

See also
QQuickItem::polish(), QQuickItem::updatePolish(), QQuickTest::qIsPolishScheduled()

Definition at line 146 of file quicktest.cpp.

References QQuickItemPrivate::get(), item, and QTest::qWaitFor().

+ Here is the call graph for this function:

◆ qWaitForPolish() [2/2]

bool QQuickTest::qWaitForPolish ( const QQuickWindow * window,
int timeout = defaultTimeout )
Since
6.4

Waits for timeout milliseconds or until qIsPolishScheduled(item) returns false for all items managed by window.

Returns true if qIsPolishScheduled(item) returns false for all items within timeout milliseconds, otherwise returns false.

The QML equivalent of this function is \l [QML]{TestCase::}{waitForPolish()}.

See also
QQuickItem::polish(), QQuickItem::updatePolish(), QQuickTest::qIsPolishScheduled()

Definition at line 166 of file quicktest.cpp.

References QQuickWindowPrivate::get(), QTest::qWaitFor(), and window().

+ Here is the call graph for this function:

◆ showView()

bool QQuickTest::showView ( QQuickView & view,
const QUrl & url )

Initialize view, set url, center in available geometry, move mouse away, show the view, wait for it to be exposed, and verify that its rootObject is not null.

Returns false if anything fails, which should be fatal in most tests. The usual way to call this function is

QVERIFY(QQuickTest::showView(window, testFileUrl("myitems.qml")));
The QQuickView class provides a window for displaying a Qt Quick user interface.
Definition qquickview.h:20
bool showView(QQuickView &view, const QUrl &url)
aWidget window() -> setWindowTitle("New Window Title")
[2]

Definition at line 509 of file viewtestutils.cpp.

References initView(), QTest::qWaitForWindowExposed(), QQuickView::rootObject(), QWindow::show(), showView(), url, and view.

Referenced by showView().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ defaultTimeout

const int QQuickTest::defaultTimeout = 5000
static

Definition at line 69 of file quicktest.h.

◆ pressedTabletButton

Qt::MouseButton QQuickTest::pressedTabletButton = Qt::NoButton
static

Definition at line 523 of file viewtestutils.cpp.

Referenced by pointerMove(), and pointerPress().

◆ pressedTabletModifiers

Qt::KeyboardModifiers QQuickTest::pressedTabletModifiers = Qt::NoModifier
static

Definition at line 524 of file viewtestutils.cpp.

Referenced by pointerMove(), and pointerPress().