aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data/cppobj.h
blob: 3b64c21e748f68c7b40c3c368d4e8007503d9d26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef CPPOBJ_H
#define CPPOBJ_H

#include <QtCore/qobject.h>
#include <QtCore/qdebug.h>
#include <QtQmlIntegration/qqmlintegration.h>

class CppObj : public QObject
{
    Q_OBJECT
    QML_ELEMENT
    Q_PROPERTY(int identifier MEMBER m_identifier CONSTANT)

public:
    explicit CppObj(int identifier = -1, QObject *parent = nullptr)
        : QObject(parent)
        , m_identifier(identifier)
    {
        qDebug() << "Object created:" << m_identifier;
    }

    ~CppObj() { qDebug() << "Object destroyed:" << m_identifier; }

private:
    int m_identifier = -1;
};

class CppBridge : public QObject
{
    Q_OBJECT
    QML_ELEMENT
    QML_SINGLETON

public:
    explicit CppBridge(QObject *parent = nullptr) : QObject{parent} {}

    Q_INVOKABLE CppObj *singleObj(int identifier) const
    {
        return new CppObj(identifier);
    }
};

#endif // CPPOBJ_H