From 14631a937d05e379e5b0f97f35f1a1e6939ccddb Mon Sep 17 00:00:00 2001 From: Christoph Sterz Date: Mon, 10 Oct 2022 10:43:56 +0200 Subject: [PATCH] More QML! --- .../qml_helloworld/qml_hello/countermanager.h | 3 ++- .../HelloWorlds/qml_helloworld/qml_hello/main.cpp | 1 + .../HelloWorlds/qml_helloworld/qml_hello/main.qml | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/countermanager.h b/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/countermanager.h index d2ec04b..bc6dbc1 100644 --- a/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/countermanager.h +++ b/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/countermanager.h @@ -6,13 +6,14 @@ class CounterManager : public QObject { Q_OBJECT + public: explicit CounterManager(QObject *parent = nullptr); + int counter() const; signals: - protected: private: int m_counter; diff --git a/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.cpp b/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.cpp index e5fa5b6..006ef19 100644 --- a/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.cpp +++ b/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.cpp @@ -13,6 +13,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; auto counterManager = new CounterManager(); engine.rootContext()->setContextProperty("_counterManager", counterManager); + const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { diff --git a/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.qml b/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.qml index 7989fc4..b34834a 100644 --- a/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.qml +++ b/Day1-IntroductionGUIFrameworks/HelloWorlds/qml_helloworld/qml_hello/main.qml @@ -7,12 +7,12 @@ Window { visible: true title: qsTr("Hello World") - Text { - text: "Counter is " + _counterManager.counter; - anchors.centerIn: parent - MouseArea{ - anchors.fill: parent - onClicked: {_counterManager.increase()} + Item { + anchors.fill: parent + + Text { + id: text + text: "Hello, World!" } } }