Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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, int delay)
 
void pointerMove (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, int delay)
 
void pointerRelease (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
 
void pointerMoveAndPress (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
 
void pointerMoveAndRelease (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &p, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
 
void pointerFlick (const QPointingDevice *dev, QQuickWindow *window, int pointId, const QPoint &from, const QPoint &to, int duration, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int delay)
 

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 = true,
QByteArray * errorMessage = nullptr )
nodiscard

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 443 of file viewtestutils.cpp.

◆ pointerFlick()

void QQuickTest::pointerFlick ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & from,
const QPoint & to,
int duration,
Qt::MouseButton button = Qt::LeftButton,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
int delay = -1 )

Definition at line 623 of file viewtestutils.cpp.

◆ pointerMove()

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

Definition at line 545 of file viewtestutils.cpp.

References QQuickTouchUtils::flush().

+ Here is the call graph for this function:

◆ pointerMoveAndPress()

void QQuickTest::pointerMoveAndPress ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & p,
Qt::MouseButton button = Qt::LeftButton,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
int delay = -1 )

Definition at line 607 of file viewtestutils.cpp.

◆ pointerMoveAndRelease()

void QQuickTest::pointerMoveAndRelease ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & p,
Qt::MouseButton button = Qt::LeftButton,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
int delay = -1 )

Definition at line 615 of file viewtestutils.cpp.

◆ pointerPress()

void QQuickTest::pointerPress ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & p,
Qt::MouseButton button = Qt::LeftButton,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
int delay = -1 )

Definition at line 513 of file viewtestutils.cpp.

References QQuickTouchUtils::flush(), pressedTabletButton, and pressedTabletModifiers.

+ Here is the call graph for this function:

◆ pointerRelease()

void QQuickTest::pointerRelease ( const QPointingDevice * dev,
QQuickWindow * window,
int pointId,
const QPoint & p,
Qt::MouseButton button = Qt::LeftButton,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
int delay = -1 )

Definition at line 577 of file viewtestutils.cpp.

References QQuickTouchUtils::flush().

+ Here is the call 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:80
#define QVERIFY(statement)
Definition qtestcase.h:59
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 80 of file quicktest.cpp.

◆ qIsPolishScheduled() [2/2]

bool QQuickTest::qIsPolishScheduled ( const QQuickWindow * window)

Definition at line 108 of file quicktest.cpp.

◆ 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 150 of file quicktest.cpp.

◆ 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 170 of file quicktest.cpp.

◆ showView()

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

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 486 of file viewtestutils.cpp.

Variable Documentation

◆ defaultTimeout

const int QQuickTest::defaultTimeout = 5000
static

Definition at line 69 of file quicktest.h.

◆ pressedTabletButton

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

Definition at line 510 of file viewtestutils.cpp.

Referenced by pointerPress().

◆ pressedTabletModifiers

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

Definition at line 511 of file viewtestutils.cpp.

Referenced by pointerPress().