doc/src/frameworks-technologies/activeqt-container.qdoc
branchRCL_3
changeset 8 3f74d0d4af4c
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the documentation of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 /*!
       
    43     \page activeqt-container.html
       
    44     \title Using ActiveX controls and COM objects in Qt
       
    45 
       
    46     \brief The QAxContainer module is a Windows-only extension for
       
    47     accessing ActiveX controls and COM objects.
       
    48 
       
    49     The QAxContainer module is part of the \l ActiveQt framework. It
       
    50     provides a library implementing a QWidget subclass, QAxWidget,
       
    51     that acts as a container for ActiveX controls, and a QObject
       
    52     subclass, QAxObject, that can be used to easily access non-visual
       
    53     COM objects. Scripting COM objects embedded using these classes
       
    54     is possible through the QAxScript, QAxScriptManager and
       
    55     QAxScriptEngine classes, and a set of \l{Tools for ActiveQt}{tools}
       
    56     makes it easy to access COM objects programmatically.
       
    57 
       
    58     The module consists of six classes
       
    59     \list 1
       
    60     \o QAxBase is an abstract class that provides an API to initialize 
       
    61        and access a COM object or ActiveX control.
       
    62     \o QAxObject provides a QObject that wraps a COM object.
       
    63     \o QAxWidget is a QWidget that wraps an ActiveX control.
       
    64     \o QAxScriptManager, QAxScript and QAxScriptEngine provide an 
       
    65        interface to the Windows Script Host.
       
    66     \endlist
       
    67 
       
    68     Some \l{ActiveQt Examples}{example applications} that use
       
    69     standard ActiveX controls to provide high-level user interface
       
    70     functionality are provided.
       
    71 
       
    72     \sa {ActiveQt Framework}
       
    73 
       
    74     Topics:
       
    75 
       
    76     \tableofcontents
       
    77 
       
    78     \section1 Using the Library
       
    79 
       
    80     To build Qt applications that can host COM objects and ActiveX controls
       
    81     link the application against the QAxContainer module by adding
       
    82 
       
    83     \snippet doc/src/snippets/code/doc_src_qaxcontainer.qdoc 0
       
    84 
       
    85     to your application's \c .pro file.
       
    86 
       
    87     \section2 Distributing QAxContainer Applications
       
    88 
       
    89     The QAxContainer library is static, so there is no need to redistribute
       
    90     any additional files when using this module. Note however that the
       
    91     ActiveX server binaries you are using might not be installed on the
       
    92     target system, so you have to ship them with your package and register
       
    93     them during the installation process of your application.
       
    94 
       
    95     \section1 Instantiating COM Objects
       
    96 
       
    97     To instantiate a COM object use the QAxBase::setControl() API, or pass
       
    98     the name of the object directly into the constructor of the QAxBase 
       
    99     subclass you are using.
       
   100 
       
   101     The control can be specified in a variety of formats, but the fastest
       
   102     and most powerful format is to use the class ID (CLSID) of the object
       
   103     directly. The class ID can be prepended with information about a remote
       
   104     machine that the object should run on, and can include a license key
       
   105     for licensed controls.
       
   106 
       
   107     \section2 Typical Error Messages
       
   108 
       
   109     ActiveQt prints error messages to the debug output when it
       
   110     encounters error situations at runtime. Usually you must run 
       
   111     your program in the debugger to see these messages (e.g. in Visual
       
   112     Studio's Debug output).
       
   113 
       
   114     \section3 Requested control could not be instantiated
       
   115 
       
   116     The control requested in QAxBase::setControl() is not installed
       
   117     on this system, or is not accessible for the current user.
       
   118 
       
   119     The control might require administrator rights, or a license key.
       
   120     If the control is licensed, pass the license key to QAxBase::setControl
       
   121     as documented.
       
   122 
       
   123     \section1 Accessing the Object API
       
   124 
       
   125     ActiveQt provides a Qt API to the COM object, and replaces COM
       
   126     datatypes with Qt equivalents.
       
   127 
       
   128     There are four ways to call APIs on the COM object:
       
   129 
       
   130     \list
       
   131     \o Generating a C++ namespace
       
   132     \o Call-by-name
       
   133     \o Through a script engine
       
   134     \o Using the native COM interfaces
       
   135     \endlist
       
   136 
       
   137     \section2 Generating a C++ Namespace
       
   138 
       
   139     To generate a C++ namespace for the type library you want to access,
       
   140     use the \l dumpcpp tool. Run this tool manually on the type library you
       
   141     want to use, or integrate it into the build system by adding the type
       
   142     libraries to the \c TYPELIBS variable in your application's \c .pro file:
       
   143 
       
   144     \snippet doc/src/snippets/code/doc_src_qaxcontainer.qdoc 1
       
   145 
       
   146     Note that \l dumpcpp might not be able to expose all APIs in the type
       
   147     library.
       
   148 
       
   149     Include the resulting header file in your code to access the
       
   150     object APIs through the generated C++ classes. See the
       
   151     \l{activeqt/qutlook}{Qutlook} example for more information.
       
   152 
       
   153     \section2 Call-by-Name
       
   154 
       
   155     Use QAxBase::dynamicCall() and QAxBase::querySubObject() as well as
       
   156     the QObject::setProperty() and QObject::property() APIs to call the
       
   157     methods and properties of the COM object through their name. Use the 
       
   158     \l dumpdoc tool to get the documentation of the Qt API for any COM 
       
   159     object and its subobjects; note that not all of the COM object's APIs
       
   160     might be available.
       
   161 
       
   162     See the \l{activeqt/webbrowser}{Webbrowser} example for more information.
       
   163 
       
   164     \section2 Calling Function Through a Script Engine
       
   165 
       
   166     A Qt application can host any ActiveScript engine installed on the system.
       
   167     The script engine can then run script code that accesses the COM objects.
       
   168 
       
   169     To instantiate a script engine, use QAxScriptManager::addObject() to
       
   170     register the COM objects you want to access from script, and 
       
   171     QAxScriptManager::load() to load the script code into the engine. Then
       
   172     call the script functions using QAxScriptManager::call() or 
       
   173     QAxScript::call().
       
   174 
       
   175     Which APIs of the COM object are available through scripting depends on 
       
   176     the script language used.
       
   177 
       
   178     The \l{testcon - An ActiveX Test Container (ActiveQt)}{ActiveX Test Container}
       
   179     demonstrates loading of script files.
       
   180 
       
   181     \section2 Calling a Function Using the Native COM Interfaces
       
   182 
       
   183     To call functions of the COM object that can not be accessed via any
       
   184     of the above methods it is possible to request the COM interface directly 
       
   185     using QAxBase::queryInterface(). To get a C++ definition of the respective
       
   186     interface classes use the \c #import directive with the type library
       
   187     provided with the control; see your compiler manual for details.
       
   188 
       
   189     \section2 Typical Error Messages
       
   190 
       
   191     ActiveQt prints error messages to the debug output when it
       
   192     encounters error situations at runtime. Usually you must run 
       
   193     your program in the debugger to see these messages (e.g. in Visual
       
   194     Studio's Debug output).
       
   195 
       
   196     \section3 QAxBase::internalInvoke: No such method
       
   197 
       
   198     A QAxBase::dynamicCall() failed - the function prototype did not
       
   199     match any function available in the object's API.
       
   200 
       
   201     \section3 Error calling IDispatch member: Non-optional parameter missing
       
   202 
       
   203     A QAxBase::dynamicCall() failed - the function prototype was correct,
       
   204     but too few parameters were provided.
       
   205 
       
   206     \section3 Error calling IDispatch member: Type mismatch in parameter n
       
   207 
       
   208     A QAxBase::dynamicCall() failed - the function prototype was correct,
       
   209     but the paramter at index \c n was of the wrong type and could 
       
   210     not be coerced to the correct type.
       
   211 
       
   212     \section3 QAxScriptManager::call(): No script provides this function
       
   213 
       
   214     You try to call a function that is provided through an engine
       
   215     that doesn't provide introspection (ie. ActivePython or 
       
   216     ActivePerl). You need to call the function directly on the
       
   217     respective QAxScript object.
       
   218 */