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!" } } }