1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of The Qt Company Ltd nor the names of its
21 **     contributors may be used to endorse or promote products derived
22 **     from this software without specific prior written permission.
23 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 //! [0]
featureList() const42 QStringList ActiveQtFactory::featureList() const
43 {
44     QStringList list;
45     list << "ActiveX1";
46     list << "ActiveX2";
47     return list;
48 }
49 
createObject(const QString & key)50 QObject *ActiveQtFactory::createObject(const QString &key)
51 {
52     if (key == "ActiveX1")
53         return new ActiveX1(parent);
54     if (key == "ActiveX2")
55         return new ActiveX2(parent);
56     return 0;
57 }
58 
metaObject(const QString & key) const59 const QMetaObject *ActiveQtFactory::metaObject(const QString &key) const
60 {
61     if (key == "ActiveX1")
62         return &ActiveX1::staticMetaObject;
63     if (key == "ActiveX2")
64         return &ActiveX2::staticMetaObject;
65 }
66 
classID(const QString & key) const67 QUuid ActiveQtFactory::classID(const QString &key) const
68 {
69     if (key == "ActiveX1")
70         return "{01234567-89AB-CDEF-0123-456789ABCDEF}";
71     ...
72     return QUuid();
73 }
74 
interfaceID(const QString & key) const75 QUuid ActiveQtFactory::interfaceID(const QString &key) const
76 {
77     if (key == "ActiveX1")
78         return "{01234567-89AB-CDEF-0123-456789ABCDEF}";
79     ...
80     return QUuid();
81 }
82 
eventsID(const QString & key) const83 QUuid ActiveQtFactory::eventsID(const QString &key) const
84 {
85     if (key == "ActiveX1")
86         return "{01234567-89AB-CDEF-0123-456789ABCDEF}";
87     ...
88     return QUuid();
89 }
90 
91 QAXFACTORY_EXPORT(
92     ActiveQtFactory,			      // factory class
93     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
94     "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
95 )
96 //! [0]
97 
98 
99 //! [1]
100 QAXFACTORY_BEGIN(
101     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
102     "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
103 )
104     QAXCLASS(Class1)
105     QAXCLASS(Class2)
106 QAXFACTORY_END()
107 //! [1]
108 
109 
110 //! [2]
111 #include <qapplication.h>
112 #include <qaxfactory.h>
113 
114 #include "theactivex.h"
115 
116 QAXFACTORY_DEFAULT(
117     TheActiveX,				  // widget class
118     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // class ID
119     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // interface ID
120     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // event interface ID
121     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
122     "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
123 )
124 //! [2]
125 
126 
127 //! [3]
128 settings->setValue("/CLSID/" + classID(key)
129                    + "/Implemented Categories/"
130                    + "/{00000000-0000-0000-000000000000}/.",
131                    QString());
132 //! [3]
133 
134 
135 //! [4]
136 settings->remove("/CLSID/" + classID(key)
137                  + "/Implemented Categories"
138                  + "/{00000000-0000-0000-000000000000}/.");
139 //! [4]
140 
141 
142 //! [5]
main(int argc,char * argv[])143 int main(int argc, char *argv[])
144 {
145     QApplication app(argc, argv);
146     if (!QAxFactory::isServer()) {
147         // initialize for stand-alone execution
148     }
149     return app.exec();
150 }
151 //! [5]
152 
153 
154 //! [6]
155 if (QAxFactory::isServer()) {
156     QAxFactory::stopServer();
157     QAxFactory::startServer(QAxFactory::SingleInstance);
158 }
159 //! [6]
160 
161 
162 //! [7]
163 #include <qaxfactory.h>
164 
165 #include "theactivex.h"
166 
167 QAXFACTORY_DEFAULT(
168     TheActiveX,				  // widget class
169     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // class ID
170     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // interface ID
171     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // event interface ID
172     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
173     "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
174 )
175 //! [7]
176 
177 
178 //! [8]
179 QAXFACTORY_EXPORT(
180     MyFactory,			              // factory class
181     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
182     "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
183 )
184 //! [8]
185 
186 
187 //! [9]
188 QAXFACTORY_BEGIN(
189     "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
190     "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
191 )
192     QAXCLASS(Class1)
193     QAXCLASS(Class2)
194 QAXFACTORY_END()
195 //! [9]
196