aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quickcontrols/chattutorial/chapter2
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2023-12-18 13:21:39 +0800
committerMitch Curtis <[email protected]>2024-01-08 10:19:19 +0800
commitc11436857fe2ee6951c97d2d58a9227120c7884c (patch)
treee162fbd1afa5980b2994929606015dda71478c55 /examples/quickcontrols/chattutorial/chapter2
parent06e42e733ed6658abbb30ba7be2e571b4533d009 (diff)
Improve chattutorial example
- Use modern QML type registration. - Fix qmllint warnings. - Tidy up code. - Update copyright year. Fixes: QTBUG-119986 Change-Id: Ibb47c929a14cd0e786acb7c7496e6cce34f624df Reviewed-by: Ulf Hermann <[email protected]>
Diffstat (limited to 'examples/quickcontrols/chattutorial/chapter2')
-rw-r--r--examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt6
-rw-r--r--examples/quickcontrols/chattutorial/chapter2/Main.qml (renamed from examples/quickcontrols/chattutorial/chapter2/main.qml)9
-rw-r--r--examples/quickcontrols/chattutorial/chapter2/chapter2.pro6
-rw-r--r--examples/quickcontrols/chattutorial/chapter2/main.cpp4
-rw-r--r--examples/quickcontrols/chattutorial/chapter2/qmldir2
5 files changed, 17 insertions, 10 deletions
diff --git a/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt b/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt
index bc531ef529..dd2835740c 100644
--- a/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt
+++ b/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
@@ -27,9 +27,9 @@ target_link_libraries(chattutorial-chapter2 PRIVATE
qt_policy(SET QTP0001 NEW)
qt_add_qml_module(chattutorial-chapter2
- URI chapter2
+ URI chattutorial
QML_FILES
- "main.qml"
+ "Main.qml"
RESOURCES
"images/Albert_Einstein.png"
diff --git a/examples/quickcontrols/chattutorial/chapter2/main.qml b/examples/quickcontrols/chattutorial/chapter2/Main.qml
index 851b482b01..daa4360fb9 100644
--- a/examples/quickcontrols/chattutorial/chapter2/main.qml
+++ b/examples/quickcontrols/chattutorial/chapter2/Main.qml
@@ -1,6 +1,8 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+pragma ComponentBehavior: Bound
+
import QtQuick
import QtQuick.Controls
@@ -29,14 +31,17 @@ ApplicationWindow {
spacing: 20
model: ["Albert Einstein", "Ernest Hemingway", "Hans Gude"]
delegate: ItemDelegate {
+ id: contactDelegate
text: modelData
width: listView.width - listView.leftMargin - listView.rightMargin
height: avatar.implicitHeight
leftPadding: avatar.implicitWidth + 32
+ required property string modelData
+
Image {
id: avatar
- source: "images/" + modelData.replace(" ", "_") + ".png"
+ source: "images/" + contactDelegate.modelData.replace(" ", "_") + ".png"
}
}
}
diff --git a/examples/quickcontrols/chattutorial/chapter2/chapter2.pro b/examples/quickcontrols/chattutorial/chapter2/chapter2.pro
index 8679db986a..88f70ce08a 100644
--- a/examples/quickcontrols/chattutorial/chapter2/chapter2.pro
+++ b/examples/quickcontrols/chattutorial/chapter2/chapter2.pro
@@ -1,7 +1,6 @@
TEMPLATE = app
QT += qml quick
-CONFIG += c++11
SOURCES += main.cpp
@@ -18,8 +17,9 @@ resources.files = \
- main.qml
-resources.prefix = qt/qml/chapter2/
+ Main.qml \
+ qmldir
+resources.prefix = qt/qml/chattutorial/
RESOURCES += resources \
qtquickcontrols2.conf
diff --git a/examples/quickcontrols/chattutorial/chapter2/main.cpp b/examples/quickcontrols/chattutorial/chapter2/main.cpp
index 07f034a827..73d4bf3b63 100644
--- a/examples/quickcontrols/chattutorial/chapter2/main.cpp
+++ b/examples/quickcontrols/chattutorial/chapter2/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QGuiApplication>
@@ -9,7 +9,7 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
- engine.load(QUrl(QStringLiteral("qrc:/qt/qml/chapter2/main.qml")));
+ engine.loadFromModule("chattutorial", "Main");
return app.exec();
}
diff --git a/examples/quickcontrols/chattutorial/chapter2/qmldir b/examples/quickcontrols/chattutorial/chapter2/qmldir
new file mode 100644
index 0000000000..1044557225
--- /dev/null
+++ b/examples/quickcontrols/chattutorial/chapter2/qmldir
@@ -0,0 +1,2 @@
+module chattutorial
+Main 1.0 Main.qml