diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2022-08-30 10:02:40 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-09-09 04:32:07 +0200 |
| commit | fc683799fee933757abdd3953048f136e750690b (patch) | |
| tree | 162256286107c43e8458c4e13fa7fcec0caebf19 /src/quickcontrolstestutils/controlstestutils.cpp | |
| parent | 2a37ff2f49140272d0122ccc097cc14c2fa4133e (diff) | |
Drop unnecessary creation contexts from Quick Controls
Bound components can only be instantiated in the context they're
declared in. Adding a context in between before instantiating a
component makes it impossible to bind the component. We want to use
bound components so that we can safely use IDs of other objects from
the same context inside the objects created from the component.
Pick-to: 6.4
Fixes: QTBUG-106042
Change-Id: I7a0e1ea3e079ccd0f5fe156f07f8bc62149c6c0a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quickcontrolstestutils/controlstestutils.cpp')
| -rw-r--r-- | src/quickcontrolstestutils/controlstestutils.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/quickcontrolstestutils/controlstestutils.cpp b/src/quickcontrolstestutils/controlstestutils.cpp index df65c3234b..de7d38db32 100644 --- a/src/quickcontrolstestutils/controlstestutils.cpp +++ b/src/quickcontrolstestutils/controlstestutils.cpp @@ -4,6 +4,7 @@ #include "controlstestutils_p.h" #include <QtTest/qsignalspy.h> +#include <QtQml/qqmlcomponent.h> #include <QtQuickControls2/qquickstyle.h> #include <QtQuickTemplates2/private/qquickabstractbutton_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> @@ -155,3 +156,16 @@ bool QQuickControlsTestUtils::doubleClickButton(QQuickAbstractButton *button) return true; } + +/*! + Allows creating QQmlComponents in C++, which is useful for tests that need + to check if items created from the component have the correct QML context. +*/ +Q_INVOKABLE QQmlComponent *QQuickControlsTestUtils::ComponentCreator::createComponent(const QByteArray &data) +{ + std::unique_ptr<QQmlComponent> component(new QQmlComponent(qmlEngine(this))); + component->setData(data, QUrl()); + if (component->isError()) + qmlWarning(this) << "Failed to create component from the following data:\n" << data; + return component.release(); +} |
