source: trunk/doc/src/frameworks-technologies/activeqt-container.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: 8.0 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-container.html
30 \title Using ActiveX controls and COM in Qt
31 \ingroup qt-activex
32
33 \brief A Windows-only extension for accessing ActiveX controls and
34 COM objects.
35
36 The QAxContainer module is part of the \l ActiveQt framework. It
37 provides a library implementing a QWidget subclass, QAxWidget,
38 that acts as a container for ActiveX controls, and a QObject
39 subclass, QAxObject, that can be used to easily access non-visual
40 COM objects. Scripting COM objects embedded using these classes
41 is possible through the QAxScript, QAxScriptManager and
42 QAxScriptEngine classes, and a set of \l{Tools for ActiveQt}{tools}
43 makes it easy to access COM objects programmatically.
44
45 The module consists of six classes
46 \list 1
47 \o QAxBase is an abstract class that provides an API to initialize
48 and access a COM object or ActiveX control.
49 \o QAxObject provides a QObject that wraps a COM object.
50 \o QAxWidget is a QWidget that wraps an ActiveX control.
51 \o QAxScriptManager, QAxScript and QAxScriptEngine provide an
52 interface to the Windows Script Host.
53 \endlist
54
55 Some \l{ActiveQt Examples}{example applications} that use
56 standard ActiveX controls to provide high-level user interface
57 functionality are provided.
58
59 \sa {ActiveQt Framework}
60
61 Topics:
62
63 \tableofcontents
64
65 \section1 Using the Library
66
67 To build Qt applications that can host COM objects and ActiveX controls
68 link the application against the QAxContainer module by adding
69
70 \snippet doc/src/snippets/code/doc_src_qaxcontainer.qdoc 0
71
72 to your application's \c .pro file.
73
74 \section2 Distributing QAxContainer Applications
75
76 The QAxContainer library is static, so there is no need to redistribute
77 any additional files when using this module. Note however that the
78 ActiveX server binaries you are using might not be installed on the
79 target system, so you have to ship them with your package and register
80 them during the installation process of your application.
81
82 \section1 Instantiating COM Objects
83
84 To instantiate a COM object use the QAxBase::setControl() API, or pass
85 the name of the object directly into the constructor of the QAxBase
86 subclass you are using.
87
88 The control can be specified in a variety of formats, but the fastest
89 and most powerful format is to use the class ID (CLSID) of the object
90 directly. The class ID can be prepended with information about a remote
91 machine that the object should run on, and can include a license key
92 for licensed controls.
93
94 \section2 Typical Error Messages
95
96 ActiveQt prints error messages to the debug output when it
97 encounters error situations at runtime. Usually you must run
98 your program in the debugger to see these messages (e.g. in Visual
99 Studio's Debug output).
100
101 \section3 Requested control could not be instantiated
102
103 The control requested in QAxBase::setControl() is not installed
104 on this system, or is not accessible for the current user.
105
106 The control might require administrator rights, or a license key.
107 If the control is licensed, pass the license key to QAxBase::setControl
108 as documented.
109
110 \section1 Accessing the Object API
111
112 ActiveQt provides a Qt API to the COM object, and replaces COM
113 datatypes with Qt equivalents.
114
115 There are four ways to call APIs on the COM object:
116
117 \list
118 \o Generating a C++ namespace
119 \o Call-by-name
120 \o Through a script engine
121 \o Using the native COM interfaces
122 \endlist
123
124 \section2 Generating a C++ Namespace
125
126 To generate a C++ namespace for the type library you want to access,
127 use the \l dumpcpp tool. Run this tool manually on the type library you
128 want to use, or integrate it into the build system by adding the type
129 libraries to the \c TYPELIBS variable in your application's \c .pro file:
130
131 \snippet doc/src/snippets/code/doc_src_qaxcontainer.qdoc 1
132
133 Note that \l dumpcpp might not be able to expose all APIs in the type
134 library.
135
136 Include the resulting header file in your code to access the
137 object APIs through the generated C++ classes. See the
138 \l{activeqt/qutlook}{Qutlook} example for more information.
139
140 \section2 Call-by-Name
141
142 Use QAxBase::dynamicCall() and QAxBase::querySubObject() as well as
143 the QObject::setProperty() and QObject::property() APIs to call the
144 methods and properties of the COM object through their name. Use the
145 \l dumpdoc tool to get the documentation of the Qt API for any COM
146 object and its subobjects; note that not all of the COM object's APIs
147 might be available.
148
149 See the \l{activeqt/webbrowser}{Webbrowser} example for more information.
150
151 \section2 Calling Function Through a Script Engine
152
153 A Qt application can host any ActiveScript engine installed on the system.
154 The script engine can then run script code that accesses the COM objects.
155
156 To instantiate a script engine, use QAxScriptManager::addObject() to
157 register the COM objects you want to access from script, and
158 QAxScriptManager::load() to load the script code into the engine. Then
159 call the script functions using QAxScriptManager::call() or
160 QAxScript::call().
161
162 Which APIs of the COM object are available through scripting depends on
163 the script language used.
164
165 The \l{testcon - An ActiveX Test Container (ActiveQt)}{ActiveX Test Container}
166 demonstrates loading of script files.
167
168 \section2 Calling a Function Using the Native COM Interfaces
169
170 To call functions of the COM object that can not be accessed via any
171 of the above methods it is possible to request the COM interface directly
172 using QAxBase::queryInterface(). To get a C++ definition of the respective
173 interface classes use the \c #import directive with the type library
174 provided with the control; see your compiler manual for details.
175
176 \section2 Typical Error Messages
177
178 ActiveQt prints error messages to the debug output when it
179 encounters error situations at runtime. Usually you must run
180 your program in the debugger to see these messages (e.g. in Visual
181 Studio's Debug output).
182
183 \section3 QAxBase::internalInvoke: No such method
184
185 A QAxBase::dynamicCall() failed - the function prototype did not
186 match any function available in the object's API.
187
188 \section3 Error calling IDispatch member: Non-optional parameter missing
189
190 A QAxBase::dynamicCall() failed - the function prototype was correct,
191 but too few parameters were provided.
192
193 \section3 Error calling IDispatch member: Type mismatch in parameter n
194
195 A QAxBase::dynamicCall() failed - the function prototype was correct,
196 but the paramter at index \c n was of the wrong type and could
197 not be coerced to the correct type.
198
199 \section3 QAxScriptManager::call(): No script provides this function
200
201 You try to call a function that is provided through an engine
202 that doesn't provide introspection (ie. ActivePython or
203 ActivePerl). You need to call the function directly on the
204 respective QAxScript object.
205*/
Note: See TracBrowser for help on using the repository browser.