More QML!

This commit is contained in:
Christoph Sterz 2022-10-10 10:43:56 +02:00
parent b6eee3a9d9
commit 14631a937d
3 changed files with 9 additions and 7 deletions

View File

@ -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;

View File

@ -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) {

View File

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