Untitled

mail@pastecode.io avatar
unknown
plain_text
10 days ago
1.3 kB
0
Indexable
Never
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QObject>

class Counter : public QObject {
    Q_OBJECT
    Q_PROPERTY(int jim READ jim WRITE tokatli NOTIFY jimChanged)
public:
    explicit Counter(QObject *parent = nullptr) : QObject(parent), m_tokatli(5) {}

    int jim() const { return m_tokatli; }

    void tokatli(int value) {
        if (m_tokatli != value) {
            printf("%d", m_tokatli);
            m_tokatli = value;
            emit jimChanged();
        }
    }

    void marco(int value) {
        emit jimChanged();
    }

    Q_INVOKABLE void startCounting() {
        tokatli(20);
    }

signals:
    void jimChanged();

private:
    int m_tokatli;
};

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    qmlRegisterType<Counter>("CounterModule", 1, 0, "Counter");

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
        &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);

    engine.load(url);

    return app.exec();
}

#include "main.moc"
Leave a Comment