source: trunk/doc/src/frameworks-technologies/activeqt-server.qdoc@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 29.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \page activeqt-server.html
30 \title Building ActiveX servers in Qt
31 \ingroup qt-activex
32
33 \brief A Windows-only static library for turning a Qt binary into a COM server.
34
35 The QAxServer module is part of the \l ActiveQt framework. It
36 consists of three classes:
37
38 \list
39 \o QAxFactory defines a factory for the creation of COM objects.
40 \o QAxBindable provides an interface between the Qt widget and the
41 COM object.
42 \o QAxAggregated can be subclassed to implement additional COM interfaces.
43 \endlist
44
45 Some \l{ActiveQt Examples}{example implementations} of ActiveX
46 controls and COM objects are provided.
47
48 \sa {ActiveQt Framework}
49
50 Topics:
51
52 \tableofcontents
53
54 \section1 Using the Library
55
56 To turn a standard Qt application into a COM server using the
57 QAxServer library you must add \c qaxserver as a CONFIG setting
58 in your \c .pro file.
59
60 An out-of-process executable server is generated from a \c .pro
61 file like this:
62
63 \snippet doc/src/snippets/code/doc_src_qaxserver.qdoc 0
64
65 To build an in-process server, use a \c .pro file like this:
66 \snippet doc/src/snippets/code/doc_src_qaxserver.qdoc 1
67
68 The files \c qaxserver.rc and \c qaxserver.def are part of the
69 framework and can be used from their usual location (specify a
70 path in the \c .pro file), or copied into the project directory.
71 You can modify these files as long as it includes any file as the
72 type library entry, ie. you can add version information or specify
73 a different toolbox icon.
74
75 The \c qaxserver configuration will cause the \c qmake tool to add the
76 required build steps to the build system:
77
78 \list
79 \o Link the binary against \c qaxserver.lib instead of \c qtmain.lib
80 \o Call the \l idc tool to generate an IDL file for the COM server
81 \o Compile the IDL into a type library using the MIDL tool (part of the
82 compiler installation)
83 \o Attach the resulting type library as a binary resource to the server
84 binary (again using the \l idc tool)
85 \o Register the server
86 \endlist
87
88 To skip the post-processing step, also set the \c qaxserver_no_postlink
89 configuration.
90
91 Additionally you can specify a version number using the \c VERSION
92 variable, e.g.
93
94 \snippet doc/src/snippets/code/doc_src_qaxserver.qdoc 2
95
96 The version number specified will be used as the version of the type
97 library and of the server when registering.
98
99 \section2 Out-of-Process vs. In-Process
100
101 Whether your COM server should run as a stand-alone executable
102 or as a shared library in the client process depends mainly on the
103 type of COM objects you want to provide in the server.
104
105 An executable server has the advantage of being able to run as a
106 stand-alone application, but adds considerable overhead to the
107 communication between the COM client and the COM object. If the
108 control has a programming error only the server process running
109 the control will crash, and the client application will probably
110 continue to run. Not all COM clients support executable servers.
111
112 An in-process server is usually smaller and has faster startup
113 time. The communication between client and server is done directly
114 through virtual function calls and does not introduce the overhead
115 required for remote procedure calls. However, if the server crashes the
116 client application is likely to crash as well, and not every
117 functionality is available for in-process servers (i.e. register in
118 the COM's running-object-table).
119
120 Both server types can use Qt either as a shared library, or statically
121 linked into the server binary.
122
123 \section2 Typical Errors During the Post-Build Steps
124
125 For the ActiveQt specific post-processing steps to work the
126 server has to meet some requirements:
127
128 \list
129 \o All controls exposed can be created with nothing but a QApplication
130 instance being present
131 \o The initial linking of the server includes a temporary type
132 library resource
133 \o All dependencies required to run the server are in the system path
134 (or in the path used by the calling environment; note that Visual
135 Studio has its own set of environment variables listed in the
136 Tools|Options|Directories dialog).
137 \endlist
138
139 If those requirements are not met one ore more of the following
140 errors are likely to occur:
141
142 \section3 The Server Executable Crashes
143
144 To generate the IDL the widgets exposed as ActiveX controls need to
145 be instantiated (the constructor is called). At this point, nothing
146 else but a QApplication object exists. Your widget constructor must
147 not rely on any other objects to be created, e.g. it should check for
148 null-pointers.
149
150 To debug your server run it with -dumpidl outputfile and check where
151 it crashes.
152
153 Note that no functions of the control are called.
154
155 \section3 The Server Executable Is Not a Valid Win32 Application
156
157 Attaching the type library corrupted the server binary. This is a
158 bug in Windows and happens only with release builds.
159
160 The first linking step has to link a dummy type library into the
161 executable that can later be replaced by idc. Add a resource file
162 with a type library to your project as demonstrated in the examples.
163
164 \section3 "Unable to locate DLL"
165
166 The build system needs to run the server executable to generate
167 the interface definition, and to register the server. If a dynamic
168 link library the server links against is not in the path this
169 might fail (e.g. Visual Studio calls the server using the
170 enivronment settings specified in the "Directories" option). Make
171 sure that all DLLs required by your server are located in a
172 directory that is listed in the path as printed in the error
173 message box.
174
175 \section3 "Cannot open file ..."
176
177 The ActiveX server could not shut down properly when the last
178 client stopped using it. It usually takes about two seconds for
179 the application to terminate, but you might have to use the task
180 manager to kill the process (e.g. when a client doesn't release
181 the controls properly).
182
183 \section1 Implementing Controls
184
185 To implement a COM object with Qt, create a subclass of QObject
186 or any existing QObject subclass. If the class is a subclass of QWidget,
187 the COM object will be an ActiveX control.
188
189 \snippet doc/src/snippets/code/doc_src_qaxserver.qdoc 3
190
191 The Q_OBJECT macro is required to provide the meta object information