Skip to content

Commit 8b90d05

Browse files
author
Kimmo
committed
Part 2 HelloWorld test
1 parent 1c86e39 commit 8b90d05

File tree

9 files changed

+165
-0
lines changed

9 files changed

+165
-0
lines changed

qmlHelloWorld/qmlHelloWorld.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
TEMPLATE = subdirs
2+
SUBDIRS += \
3+
src \
4+
test_runner
5+
6+
test_runner.depends = src

qmlHelloWorld/src/HelloWorld.qml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import QtQuick 2.0
2+
import QtQuick.Dialogs 1.1
3+
import QtQuick.Controls 1.0
4+
5+
Item {
6+
id: world
7+
width: 400
8+
height: 200
9+
10+
// Expose helloText's text property with the name "textThing" here.
11+
// BEGIN SOLUTION
12+
property alias textThing: helloText.text
13+
// END SOLUTION
14+
15+
Text {
16+
id: helloText
17+
x: 38
18+
y: 41
19+
width: 325
20+
height: 99
21+
color: "blue"
22+
font.pixelSize: 55
23+
}
24+
}

qmlHelloWorld/src/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <QGuiApplication>
2+
#include <QQmlApplicationEngine>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
7+
8+
QGuiApplication app(argc, argv);
9+
10+
QQmlApplicationEngine engine;
11+
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
12+
if (engine.rootObjects().isEmpty())
13+
return -1;
14+
return app.exec();
15+
}

qmlHelloWorld/src/main.qml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import QtQuick 2.0
2+
import QtQuick.Window 2.2
3+
4+
Window {
5+
id: window
6+
width: 400
7+
visible: true
8+
height: 220
9+
title: qsTr("Hello World")
10+
11+
HelloWorld {
12+
textThing: "Don't Panic!"
13+
width: 350
14+
height: 200
15+
anchors.centerIn: parent
16+
}
17+
18+
}

qmlHelloWorld/src/qml.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>HelloWorld.qml</file>
5+
</qresource>
6+
</RCC>

qmlHelloWorld/src/src.pro

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
QT += quick
2+
TARGET = main
3+
CONFIG += c++11
4+
5+
# The following define makes your compiler emit warnings if you use
6+
# any feature of Qt which as been marked deprecated (the exact warnings
7+
# depend on your compiler). Please consult the documentation of the
8+
# deprecated API in order to know how to port your code away from it.
9+
DEFINES += QT_DEPRECATED_WARNINGS
10+
11+
# You can also make your code fail to compile if you use deprecated APIs.
12+
# In order to do so, uncomment the following line.
13+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
14+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
15+
16+
SOURCES += main.cpp
17+
18+
RESOURCES += qml.qrc
19+
20+
OTHER_FILES += \
21+
HelloWorld.qml \
22+
main.qml
23+
24+
# Additional import path used to resolve QML modules in Qt Creator's code model
25+
QML_IMPORT_PATH =
26+
27+
# Additional import path used to resolve QML modules just for Qt Quick Designer
28+
QML_DESIGNER_IMPORT_PATH =
29+
30+
# Default rules for deployment.
31+
qnx: target.path = /tmp/$${TARGET}/bin
32+
else: unix:!android: target.path = /opt/$${TARGET}/bin
33+
!isEmpty(target.path): INSTALLS += target
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
TEMPLATE = app
2+
TARGET = tst_helloworld
3+
QT += quick core testlib
4+
CONFIG += c++11 warn_on qmltestcase
5+
CONFIG -= app_bundle
6+
7+
# The following define makes your compiler emit warnings if you use
8+
# any feature of Qt which as been marked deprecated (the exact warnings
9+
# depend on your compiler). Please consult the documentation of the
10+
# deprecated API in order to know how to port your code away from it.
11+
DEFINES += QT_DEPRECATED_WARNINGS
12+
13+
# You can also make your code fail to compile if you use deprecated APIs.
14+
# In order to do so, uncomment the following line.
15+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
16+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17+
18+
SOURCES += tst_helloworld.cpp
19+
20+
OTHER_FILES += tst_helloworld.qml
21+
22+
RESOURCES += \
23+
$$PWD/../src/qml.qrc
24+
25+
INCLUDEPATH += $$PWD/../src
26+
27+
# Additional import path used to resolve QML modules in Qt Creator's code model
28+
QML2_IMPORT_PATH = $$PWD/../src/qml.qrc
29+
30+
# Additional import path used to resolve QML modules just for Qt Quick Designer
31+
QML_DESIGNER_IMPORT_PATH =
32+
33+
# Default rules for deployment.
34+
qnx: target.path = /tmp/$${TARGET}/bin
35+
else: unix:!android: target.path = /opt/$${TARGET}/bin
36+
!isEmpty(target.path): INSTALLS += target
37+
38+
DISTFILES += \
39+
tst_helloworld
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <QtQuickTest/quicktest.h>
2+
QUICK_TEST_MAIN(tst_helloworld)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import QtQuick 2.0
2+
import QtTest 1.0
3+
import QtQuick.Window 2.2
4+
import "../src/" 1.00
5+
6+
TestCase {
7+
name: "tst_helloworld"
8+
9+
HelloWorld {
10+
id: helloWorld
11+
textThing: "Hello World!"
12+
}
13+
14+
function quickPOINT(function_name, point) {
15+
console.info("TMC:" + function_name + "." + point);
16+
}
17+
18+
function test_world() {
19+
quickPOINT("tst_helloworld::test_world", "world_point");
20+
compare(helloWorld.textThing, "Hello World!")
21+
}
22+
}

0 commit comments

Comments
 (0)