QAxBase Class
The QAxBase class is an abstract class that provides an API to initialize and access a COM object. More...
Public Types
| (alias) | PropertyBag |
Properties
- control : QString
Public Functions
| QString | control() const |
| bool | setControl(const QString &) |
Detailed Description
QAxBase is an abstract class that cannot be used directly, and is instantiated through the subclasses QAxObject and QAxWidget. This class provides the API to access the COM object directly through its IUnknown implementation. If the COM object implements the IDispatch interface, the properties and methods of that object become available as Qt properties and slots.
connect(buttonBack, SIGNAL(clicked()), webBrowser, SLOT(GoBack()));
Properties exposed by the object's IDispatch implementation can be read and written through the property system provided by the Qt Object Model (both subclasses are QObjects, so you can use QObject::setProperty() and QObject::property()). Properties with multiple parameters are not supported.
activeX->setProperty("text", "some text"); int value = activeX->property("value");
Write-functions for properties and other methods exposed by the object's IDispatch implementation can be called directly using dynamicCall(), or indirectly as slots connected to a signal.
webBrowser->dynamicCall("GoHome()");
Outgoing events supported by the COM object are emitted as standard Qt signals.
connect(webBrowser, SIGNAL(TitleChanged(QString)), this, SLOT(setCaption(QString)));
QAxBase transparently converts between COM data types and the equivalent Qt data types. Some COM types have no equivalent Qt data structure.
Supported COM datatypes are listed in the first column of following table. The second column is the Qt type that can be used with the QObject property functions. The third column is the Qt type that is used in the prototype of generated signals and slots for in-parameters, and the last column is the Qt type that is used in the prototype of signals and slots for out-parameters.
| COM type | Qt property | in-parameter | out-parameter |
|---|---|---|---|
| VARIANT_BOOL | bool | bool | bool& |
| BSTR | QString | const QString& | QString& |
| char, short, int, long | int | int | int& |
| uchar, ushort, uint, ulong | uint | uint | uint& |
| float, double | double | double | double& |
| DATE | QDateTime | const QDateTime& | QDateTime& |
| CY | qlonglong | qlonglong | qlonglong& |
| OLE_COLOR | QColor | const QColor& | QColor& |
| SAFEARRAY(VARIANT) | QList<QVariant> | const QList<QVariant>& | QList<QVariant>& |
| SAFEARRAY(int), SAFEARRAY(double), SAFEARRAY(Date) | QList<QVariant> | const QList<QVariant>& | QList<QVariant>& |
| SAFEARRAY(BYTE) | QByteArray | const QByteArray& | QByteArray& |
| SAFEARRAY(BSTR) | QStringList | const QStringList& | QStringList& |
| VARIANT | type-dependent | const QVariant& | QVariant& |
| IFontDisp* | QFont | const QFont& | QFont& |
| IPictureDisp* | QPixmap | const QPixmap& | QPixmap& |
| IDispatch* | QAxObject* | QAxBase::asVariant() | QAxObject* (return value) |
| IUnknown* | QAxObject* | QAxBase::asVariant() | QAxObject* (return value) |
| SCODE, DECIMAL | unsupported | unsupported | unsupported |
| VARIANT* (Since Qt 4.5) | unsupported | QVariant& | QVariant& |
Supported are also enumerations, and typedefs to supported types.
To call the methods of a COM interface described by the following IDL
dispinterface IControl
{
properties:
[id(1)] BSTR text;
[id(2)] IFontDisp *font;
methods:
[id(6)] void showColumn([in] int i);
[id(3)] bool addColumn([in] BSTR t);
[id(4)] int fillList([in, out] SAFEARRAY(VARIANT) *list);
[id(5)] IDispatch *item([in] int i);
};
use the QAxBase API like this:
QAxObject object("<CLSID>"); QString text = object.property("text").toString(); object.setProperty("font", QFont("Times New Roman", 12)); connect(this, SIGNAL(clicked(int)), &object, SLOT(showColumn(int))); bool ok = object.dynamicCall("addColumn(const QString&)", "Column 1").toBool(); QList<QVariant> varlist; QList<QVariant> parameters; parameters << QVariant(varlist); int n = object.dynamicCall("fillList(QList<QVariant>&)", parameters).toInt(); QAxObject *item = object.querySubItem("item(int)", 5);
Note that the QList the object should fill has to be provided as an element in the parameter list of QVariants.
If you need to access properties or pass parameters of unsupported datatypes you must access the COM object directly through its IDispatch implementation or other interfaces. Those interfaces can be retrieved through queryInterface().
IUnknown *iface = 0; activeX->queryInterface(IID_IUnknown, (void**)&iface); if (iface) { // use the interface iface->Release(); }
To get the definition of the COM interfaces you will have to use the header files provided with the component you want to use. Some compilers can also import type libraries using the #import compiler directive. See the component documentation to find out which type libraries you have to import, and how to use them.
If you need to react to events that pass parameters of unsupported datatypes you can use the generic signal that delivers the event data as provided by the COM event.
See also QAxObject, QAxWidget, QAxScript, and ActiveQt Framework.
Member Type Documentation
[alias] QAxBase::PropertyBag
This is a type alias for QMap<QString, QVariant>.
A QMap<QString,QVariant> that can store properties as name:value pairs.
Property Documentation
control : QString
This property holds the name of the COM object wrapped by this QAxBase object.
Setting this property initializes the COM object. Any COM object previously set is shut down.
The most efficient way to set this property is by using the registered component's UUID, e.g.
ctrl->setControl("{8E27C92B-1264-101C-8A2F-040224009C02}");
The second fastest way is to use the registered control's class name (with or without version number), e.g.
ctrl->setControl("MSCal.Calendar");
The slowest, but easiest way to use is to use the control's full name, e.g.
ctrl->setControl("Calendar Control 9.0");
It is also possible to initialize the object from a file, e.g.
ctrl->setControl("c:/files/file.doc");
If the component's UUID is used the following patterns can be used to initialize the control on a remote machine, to initialize a licensed control or to connect to a running object:
- To initialize the control on a different machine use the following pattern:
<domain/username>:<password>@server/{8E27C92B-1264-101C-8A2F-040224009C02}
- To initialize a licensed control use the following pattern:
{8E27C92B-1264-101C-8A2F-040224009C02}:<LicenseKey> - To connect to an already running object use the following pattern:
{8E27C92B-1264-101C-8A2F-040224009C02}&
The first two patterns can be combined, e.g. to initialize a licensed control on a remote machine:
ctrl->setControl("DOMAIN/user:password@server/{8E27C92B-1264-101C-8A2F-040224009C02}:LicenseKey");
The control's read function always returns the control's UUID, if provided including the license key, and the name of the server, but not including the username, the domain or the password.
Access functions:
| QString | control() const |
| bool | setControl(const QString &) |
See also setClassContext().