#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QObject>
#include <QQuickItem>

class ParentItem : public QObject
{
    Q_OBJECT
    Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)

public:
    explicit ParentItem(QObject *parent = nullptr) : QObject(parent), m_opacity(1.0) {}

    qreal opacity() const {
        return m_opacity;
    }

public slots:
    void setOpacity(qreal opacity) {
        if (m_opacity != opacity) {
            m_opacity = opacity;
            emit opacityChanged();
        }
    }

signals:
    void opacityChanged();

private:
    qreal m_opacity;
};

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

    // Create the ParentItem instance
    ParentItem parentItem;

    // Create the QML application engine
    QQmlApplicationEngine engine;

    // Expose the ParentItem instance to QML
    engine.rootContext()->setContextProperty("parentItem", &parentItem);

    // Load the main QML file
    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"

