aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data/shadowingSingleton.h
blob: 6a40db17e3cb10e10e96c4caa63ae8706010db56 (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
47
48
49
50
51
52
53
54
55
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef SHADOWINGSINGLETON_H
#define SHADOWINGSINGLETON_H

#include <QtCore/qobject.h>
#include <QtQml/qqmlengine.h>
#include <QtQmlIntegration/qqmlintegration.h>

class ShadowingSingletonBase : public QObject
{
    Q_OBJECT

public:
    using QObject::QObject;

    Q_INVOKABLE virtual QString aFunction() const = 0;

signals:
    void aSignal(int);
};


class ShadowingSingleton : public ShadowingSingletonBase
{
    Q_OBJECT
public:

    explicit ShadowingSingleton(QObject *parent = nullptr)
        : ShadowingSingletonBase(parent)
    {}

    Q_INVOKABLE QString aFunction() const override
    {
        return QStringLiteral("Hej");
    }
};

class ShadowingSingletonForeign
{
    Q_GADGET
    QML_FOREIGN(ShadowingSingletonBase)
    QML_SINGLETON
    QML_NAMED_ELEMENT(ShadowingSingleton)
public:
    static ShadowingSingletonBase *create(QQmlEngine *engine, QJSEngine *scriptEngine)
    {
        Q_UNUSED(engine);
        Q_UNUSED(scriptEngine)
        return new ShadowingSingleton;
    }
};

#endif // SHADOWINGSINGLETON_H