QQuickTest Namespace | Qt Quick Test 6.7.3
Description: The QQuickTest namespace contains all the functions and macros related to Qt Quick Test.

- Qt 6.7
- Qt Quick Test
- QQuickTest Namespace
- Qt 6.7.3 Reference Documentation

# QQuickTest Namespace

The QQuickTest namespace contains all the functions and macros related to Qt Quick Test. More...

Header: | #include <QtQuickTest>

## Functions

`(since 6.4)` int | qIsPolishScheduled(const QQuickWindow *window)
`(since 6.4)` int | qWaitForPolish(const QQuickWindow *window, int timeout = defaultTimeout)

## Macros

| QUICK_TEST_MAIN(name)
| QUICK_TEST_MAIN_WITH_SETUP(name, QuickTestSetupClass)

## Detailed Description

See the Introduction to Qt Quick Test for information about how to write Qt Quick unit tests.

To link to the Qt Quick Test C++ library, see Qt Quick Test C++ API.

See also Executing C++ Before QML Tests.

## Function Documentation

### `[since 6.4]` int QQuickTest::qIsPolishScheduled(const QQuickWindow *window)

This function overloads qIsPolishScheduled().

Returns `true` if there are any items managed by this window for which `qIsPolishScheduled(item)` returns `true`, otherwise returns `false`.

For example, if an item somewhere within the scene may or may not be polished, but you need to wait for it if it is, you can use the following code:

     if (QQuickTest::qIsPolishScheduled(window))
         QVERIFY(QQuickTest::qWaitForPolish(window));

The QML equivalent of this function is isPolishScheduled().

This function was introduced in Qt 6.4.

See also QQuickItem::polish(), QQuickItem::updatePolish(), and QQuickTest::qWaitForPolish().

### `[since 6.4]` int QQuickTest::qWaitForPolish(const QQuickWindow *window, int timeout = defaultTimeout)

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 waitForPolish().

This function was introduced in Qt 6.4.

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

## Macro Documentation

### QUICK_TEST_MAIN(name)

Sets up the entry point for a Qt Quick Test application. The name argument uniquely identifies this set of tests.

     #include <QtQuickTest>
     QUICK_TEST_MAIN(example)

Note: The macro assumes that your test sources are in the current directory, unless the `QUICK_TEST_SOURCE_DIR` environment variable is set.

See also QUICK_TEST_MAIN_WITH_SETUP() and Running Qt Quick Tests.

### QUICK_TEST_MAIN_WITH_SETUP(name, QuickTestSetupClass)

Sets up the entry point for a Qt Quick Test application. The name argument uniquely identifies this set of tests.

This macro is identical to QUICK_TEST_MAIN(), except that it takes an additional argument QuickTestSetupClass, the type of a QObject-derived class which will be instantiated. With this class it is possible to define additional setup code to execute before running the QML test.

Note: The macro assumes that your test sources are in the current directory, unless the `QUICK_TEST_SOURCE_DIR` environment variable is set.

The following snippet demonstrates the use of this macro:

     // src_qmltest_qquicktest.cpp
     #include <QtQuickTest>
     #include <QQmlEngine>
     #include <QQmlContext>
     #include <QGuiApplication>

     class Setup : public QObject
     {
         Q_OBJECT

     public:
         Setup() {}

     public slots:
         void applicationAvailable()
         {
             // Initialization that only requires the QGuiApplication object to be available
         }

         void qmlEngineAvailable(QQmlEngine *engine)
         {
             // Initialization requiring the QQmlEngine to be constructed
             engine->rootContext()->setContextProperty("myContextProperty", QVariant(true));
         }

         void cleanupTestCase()
         {
             // Implement custom resource cleanup
         }
     };

     QUICK_TEST_MAIN_WITH_SETUP(mytest, Setup)

     #include "src_qmltest_qquicktest.moc"

See also QUICK_TEST_MAIN() and Running Qt Quick Tests.