aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest/doc/snippets/src_qmltest_qquicktest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmltest/doc/snippets/src_qmltest_qquicktest.cpp')
-rw-r--r--src/qmltest/doc/snippets/src_qmltest_qquicktest.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/qmltest/doc/snippets/src_qmltest_qquicktest.cpp b/src/qmltest/doc/snippets/src_qmltest_qquicktest.cpp
new file mode 100644
index 0000000000..32e5c984ac
--- /dev/null
+++ b/src/qmltest/doc/snippets/src_qmltest_qquicktest.cpp
@@ -0,0 +1,39 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [2]
+// 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"
+//! [2]