|  | Home · All Classes · Modules

# QAxContainer Module

The QAxContainer module provides classes for accessing ActiveX controls and COM objects. It is only available in the commercial version of PyQt for Windows. More...

## Detailed Description

The QAxContainer module provides classes for accessing ActiveX controls and COM objects. It is only available in the commercial version of PyQt for Windows.

To import the module use, for example, the following statement:

    from PyQt4 import QAxContainer

The QAxContainer module provides a QWidget subclass, QAxWidget, that acts as a container for ActiveX controls, and a QObject subclass, QAxObject, that can be used to easily access non-visual COM objects.

The module consists of three classes

1. QAxBase is an abstract class that provides an API to initialize and access a COM object or ActiveX control.
2. QAxObject provides a QObject that wraps a COM object.
3. QAxWidget is a QWidget that wraps an ActiveX control.

Topics:

- Instantiating COM Objects
- - Typical Error Messages
  - - Requested control could not be instantiated
- Accessing the Object API
- - Call-by-Name
  - Calling a Function Using the Native COM Interfaces
  - Typical Error Messages
  - - QAxBase.internalInvoke: No such method
    - Error calling IDispatch member: Non-optional parameter missing
    - Error calling IDispatch member: Type mismatch in parameter n

### Instantiating COM Objects

To instantiate a COM object use the QAxBase.setControl() API, or pass the name of the object directly into the constructor of the QAxBase subclass you are using.

The control can be specified in a variety of formats, but the fastest and most powerful format is to use the class ID (CLSID) of the object directly. The class ID can be prepended with information about a remote machine that the object should run on, and can include a license key for licensed controls.

#### Typical Error Messages

ActiveQt prints error messages to the debug output when it encounters error situations at runtime. Usually you must run your program in the debugger to see these messages (e.g. in Visual Studio's Debug output).

##### Requested control could not be instantiated

The control requested in QAxBase.setControl() is not installed on this system, or is not accessible for the current user.

The control might require administrator rights, or a license key. If the control is licensed, pass the license key to QAxBase.setControl as documented.

### Accessing the Object API

ActiveQt provides a Qt API to the COM object, and replaces COM datatypes with Qt equivalents.

There are two ways to call APIs on the COM object:

- Call-by-name
- Using the native COM interfaces

#### Call-by-Name

Use QAxBase.dynamicCall() and QAxBase.querySubObject() as well as the QObject.setProperty() and QObject.property() APIs to call the methods and properties of the COM object through their name. Use the dumpdoc tool to get the documentation of the Qt API for any COM object and its subobjects; note that not all of the COM object's APIs might be avaiable.

See the Webbrowser example for more information.

#### Calling a Function Using the Native COM Interfaces

To call functions of the COM object that can not be accessed via any of the above methods it is possible to request the COM interface directly using QAxBase.queryInterface(). To get a C++ definition of the respective interface classes use the `#import` directive with the type library provided with the control; see your compiler manual for details.

#### Typical Error Messages

ActiveQt prints error messages to the debug output when it encounters error situations at runtime. Usually you must run your program in the debugger to see these messages (e.g. in Visual Studio's Debug output).

##### QAxBase.internalInvoke: No such method

A QAxBase.dynamicCall() failed - the function prototype did not match any function available in the object's API.

##### Error calling IDispatch member: Non-optional parameter missing

A QAxBase.dynamicCall() failed - the function prototype was correct, but too few parameters were provided.

##### Error calling IDispatch member: Type mismatch in parameter n

A QAxBase.dynamicCall() failed - the function prototype was correct, but the paramter at index `n` was of the wrong type and could not be coerced to the correct type.