More QML!
This commit is contained in:
parent
b6eee3a9d9
commit
14631a937d
@ -6,13 +6,14 @@
|
|||||||
class CounterManager : public QObject
|
class CounterManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CounterManager(QObject *parent = nullptr);
|
explicit CounterManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
int counter() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
int m_counter;
|
int m_counter;
|
||||||
|
@ -13,6 +13,7 @@ int main(int argc, char *argv[])
|
|||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
auto counterManager = new CounterManager();
|
auto counterManager = new CounterManager();
|
||||||
engine.rootContext()->setContextProperty("_counterManager", counterManager);
|
engine.rootContext()->setContextProperty("_counterManager", counterManager);
|
||||||
|
|
||||||
const QUrl url(QStringLiteral("qrc:/main.qml"));
|
const QUrl url(QStringLiteral("qrc:/main.qml"));
|
||||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
||||||
&app, [url](QObject *obj, const QUrl &objUrl) {
|
&app, [url](QObject *obj, const QUrl &objUrl) {
|
||||||
|
@ -7,12 +7,12 @@ Window {
|
|||||||
visible: true
|
visible: true
|
||||||
title: qsTr("Hello World")
|
title: qsTr("Hello World")
|
||||||
|
|
||||||
Text {
|
Item {
|
||||||
text: "Counter is " + _counterManager.counter;
|
anchors.fill: parent
|
||||||
anchors.centerIn: parent
|
|
||||||
MouseArea{
|
Text {
|
||||||
anchors.fill: parent
|
id: text
|
||||||
onClicked: {_counterManager.increase()}
|
text: "Hello, World!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user