1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef INTERFACES_H
30#define INTERFACES_H
31
32#include <QtQml/qqml.h>
33
34struct Interface {
35};
36
37QT_BEGIN_NAMESPACE
38#define MyInterface_iid "io.qt.bugreports.Interface"
39Q_DECLARE_INTERFACE(Interface, MyInterface_iid);
40QT_END_NAMESPACE
41
42class A : public QObject, Interface {
43 Q_OBJECT
44 Q_INTERFACES(Interface)
45};
46
47class B : public QObject, Interface {
48 Q_OBJECT
49 Q_INTERFACES(Interface)
50};
51
52class C : public QObject {
53 Q_OBJECT
54};
55
56struct Interface2
57{
58 Q_GADGET
59 QML_INTERFACE
60};
61
62QT_BEGIN_NAMESPACE
63#define MyInterface2_iid "io.qt.bugreports.Interface2"
64Q_DECLARE_INTERFACE(Interface2, MyInterface2_iid);
65QT_END_NAMESPACE
66
67class A2 : public QObject, Interface2 {
68 Q_OBJECT
69 QML_ELEMENT
70 Q_INTERFACES(Interface2)
71};
72
73class B2 : public QObject, Interface2 {
74 Q_OBJECT
75 QML_ELEMENT
76 Q_INTERFACES(Interface2)
77};
78
79class C2 : public QObject {
80 Q_OBJECT
81 QML_ELEMENT
82};
83
84class InterfaceConsumer : public QObject {
85 Q_OBJECT
86 Q_PROPERTY(Interface *i READ interface WRITE setInterface NOTIFY interfaceChanged)
87 Q_PROPERTY(int testValue READ testValue NOTIFY testValueChanged)
88
89public:
90
91 Interface* interface() const
92 {
93 return m_interface;
94 }
95 void setInterface(Interface* interface)
96 {
97 QObject* object = reinterpret_cast<QObject*>(interface);
98 m_testValue = object->property(name: "i").toInt();
99 emit testValueChanged();
100 if (m_interface == interface)
101 return;
102
103 m_interface = interface;
104 emit interfaceChanged();
105 }
106
107 int testValue() {
108 return m_testValue;
109 }
110
111signals:
112 void interfaceChanged();
113 void testValueChanged();
114
115private:
116 Interface* m_interface = nullptr;
117 int m_testValue = 0;
118};
119
120
121class InterfaceConsumer2 : public QObject
122{
123 Q_OBJECT
124
125 Q_PROPERTY(Interface2 *i READ interface WRITE setInterface NOTIFY interfaceChanged)
126 Q_PROPERTY(int testValue READ testValue NOTIFY testValueChanged)
127
128 QML_ELEMENT
129
130public:
131
132 Interface2* interface() const
133 {
134 return m_interface;
135 }
136 void setInterface(Interface2* interface2)
137 {
138 QObject* object = reinterpret_cast<QObject*>(interface2);
139 m_testValue = object->property(name: "i").toInt();
140 emit testValueChanged();
141 if (m_interface == interface2)
142 return;
143
144 m_interface = interface2;
145 emit interfaceChanged();
146 }
147
148 int testValue() {
149 return m_testValue;
150 }
151
152signals:
153 void interfaceChanged();
154 void testValueChanged();
155
156private:
157 Interface2 *m_interface = nullptr;
158 int m_testValue = 0;
159};
160
161#endif // INTERFACES_H
162

source code of qtdeclarative/tests/auto/qml/qqmlproperty/interfaces.h