aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrolstestutils/controlstestutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quickcontrolstestutils/controlstestutils.cpp')
-rw-r--r--src/quickcontrolstestutils/controlstestutils.cpp14
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();
+}