IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QQuickTest Namespace

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

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QQuickTest Namespace

  • Header: QtQuickTest

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

Function Documentation

 

[since 5.13] bool QQuickTest::qIsPolishScheduled(const QQuickItem *item)

Returns true if updatePolish() has not been called on item since the last call to 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:

 
Sélectionnez
QVERIFY(QQuickTest::qIsPolishScheduled(item));
QVERIFY(QQuickTest::qWaitForItemPolished(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 isPolishScheduled().

This function was introduced in Qt 5.13.

See Also

[since 6.4] bool 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:

 
Sélectionnez
if (QQuickTest::qIsPolishScheduled(window))
    QVERIFY(QQuickTest::qWaitForPolish(window));

This function was introduced in Qt 6.4.

See Also

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

Waits for timeout milliseconds or until updatePolish() has been called on item.

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

This function was introduced in Qt 6.4.

See Also

[since 6.4] bool 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.

This function was introduced in Qt 6.4.

See Also

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.

 
Sélectionnez
#include <QtQuickTest>
QUICK_TEST_MAIN(example)

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(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, a pointer to a QObject-derived class. With this class it is possible to define additional setup code to execute before running the QML test.

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:

 
Sélectionnez
// src_qmltest_qquicktest.cpp
#include <QtQuickTest>
#include <QQmlEngine>
#include <QQmlContext>

class Setup : public QObject
{
    Q_OBJECT

public:
    Setup() {}

public slots:
    void qmlEngineAvailable(QQmlEngine *engine)
    {
        engine->rootContext()->setContextProperty("myContextProperty", QVariant(true));
    }
};

QUICK_TEST_MAIN_WITH_SETUP(mytest, Setup)

#include "src_qmltest_qquicktest.moc"
See Also

Obsolete Members for QQuickTest

The following members of class QQuickTest are deprecated. We strongly advise against using them in new code.

Obsolete Function Documentation

 
[since 5.13] bool QQuickTest::qWaitForItemPolished(const QQuickItem *item, int timeout = defaultTimeout)

This function is deprecated since 6.4. We strongly advise against using it in new code.

Use qWaitForPolish() instead.

Waits for timeout milliseconds or until updatePolish() has been called on item.

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

The QML equivalent of this function is waitForItemPolished().

This function was introduced in Qt 5.13.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+