Qt 4.8
|
The QAxBase class is an abstract class that provides an API to initialize and access a COM object. More...
#include <qaxbase.h>
Public Types | |
typedef QMap< QString, QVariant > | PropertyBag |
A QMap<QString,QVariant> that can store properties as name:value pairs. More... | |
Signals | |
void | exception (int, const QString &, const QString &, const QString &) |
This signal is emitted when the COM object throws an exception while called using the OLE automation interface IDispatch. More... | |
void | propertyChanged (const QString &) |
If the COM object supports property notification, this signal gets emitted when the property called name is changed. More... | |
void | signal (const QString &, int, void *) |
This generic signal gets emitted when the COM object issues the event name. More... | |
Public Functions | |
QVariant | asVariant () const |
Returns a QVariant that wraps the COM object. More... | |
virtual const char * | className () const =0 |
virtual void | clear () |
Disconnects and destroys the COM object. More... | |
QString | control () const |
the name of the COM object wrapped by this QAxBase object. More... | |
void | disableClassInfo () |
Disables the class info generation for this ActiveX container. More... | |
void | disableEventSink () |
Disables the event sink implementation for this ActiveX container. More... | |
void | disableMetaObject () |
Disables the meta object generation for this ActiveX container. More... | |
QVariant | dynamicCall (const char *name, const QVariant &v1=QVariant(), const QVariant &v2=QVariant(), const QVariant &v3=QVariant(), const QVariant &v4=QVariant(), const QVariant &v5=QVariant(), const QVariant &v6=QVariant(), const QVariant &v7=QVariant(), const QVariant &v8=QVariant()) |
Calls the COM object's method function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8, and returns the value returned by the method, or an invalid QVariant if the method does not return a value or when the function call failed. More... | |
QVariant | dynamicCall (const char *name, QList< QVariant > &vars) |
Calls the COM object's method function, passing the parameters in vars, and returns the value returned by the method. More... | |
QString | generateDocumentation () |
Returns a rich text string with documentation for the wrapped COM object. More... | |
bool | isNull () const |
Returns true if there is no COM object loaded by this wrapper; otherwise return false. More... | |
virtual const QMetaObject * | metaObject () const |
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo interface implementations in the COM object. More... | |
PropertyBag | propertyBag () const |
Returns a name:value map of all the properties exposed by the COM object. More... | |
virtual bool | propertyWritable (const char *) const |
Returns true if the property prop is writable; otherwise returns false. More... | |
QAxBase (IUnknown *iface=0) | |
Creates a QAxBase object that wraps the COM object iface. More... | |
virtual QObject * | qObject () const =0 |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
long | queryInterface (const QUuid &, void **) const |
Requests the interface uuid from the COM object and sets the value of iface to the provided interface, or to 0 if the requested interface could not be provided. More... | |
QAxObject * | querySubObject (const char *name, const QVariant &v1=QVariant(), const QVariant &v2=QVariant(), const QVariant &v3=QVariant(), const QVariant &v4=QVariant(), const QVariant &v5=QVariant(), const QVariant &v6=QVariant(), const QVariant &v7=QVariant(), const QVariant &v8=QVariant()) |
Returns a pointer to a QAxObject wrapping the COM object provided by the method or property name, passing passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8. More... | |
QAxObject * | querySubObject (const char *name, QList< QVariant > &vars) |
The QVariant objects in vars are updated when the method has out-parameters. More... | |
bool | setControl (const QString &) |
void | setPropertyBag (const PropertyBag &) |
Sets the properties of the COM object to the corresponding values in bag. More... | |
virtual void | setPropertyWritable (const char *, bool) |
Sets the property prop to writable if ok is true, otherwise sets prop to be read-only. More... | |
QStringList | verbs () const |
Returns the list of verbs that the COM object can execute. More... | |
virtual | ~QAxBase () |
Shuts down the COM object and destroys the QAxBase object. More... | |
Protected Functions | |
void | connectNotify () |
Connects to all event interfaces of the object. More... | |
long | indexOfVerb (const QString &verb) const |
virtual bool | initialize (IUnknown **ptr) |
This virtual function is called by setControl() and creates the requested COM object. More... | |
bool | initializeActive (IUnknown **ptr) |
Connects to an active instance running on the current machine, and returns the IUnknown interface to the running object in ptr. More... | |
void | initializeFrom (QAxBase *that) |
Used by subclasses generated with dumpcpp to implement cast-operators. More... | |
bool | initializeFromFile (IUnknown **ptr) |
Creates the COM object handling the filename in the control property, and returns the IUnknown interface to the object in ptr. More... | |
bool | initializeLicensed (IUnknown **ptr) |
Creates an instance of a licensed control, and returns the IUnknown interface to the object in ptr. More... | |
bool | initializeRemote (IUnknown **ptr) |
Creates the instance on a remote server, and returns the IUnknown interface to the object in ptr. More... | |
void | internalRelease () |
Used by subclasses generated with dumpcpp to balance reference count. More... | |
Private Functions | |
bool | dynamicCallHelper (const char *name, void *out, QList< QVariant > &var, QByteArray &type) |
bool | initializeLicensedHelper (void *factory, const QString &key, IUnknown **ptr) |
int | internalInvoke (QMetaObject::Call, int index, void **v) |
QAxMetaObject * | internalMetaObject () const |
int | internalProperty (QMetaObject::Call, int index, void **v) |
virtual const QMetaObject * | parentMetaObject () const =0 |
Properties | |
QAxBasePrivate * | d |
Static Private Attributes | |
static QMetaObject | staticMetaObject |
Friends | |
void * | qax_createObjectWrapper (int, IUnknown *) |
class | QAxEventSink |
The QAxBase class is an abstract class that provides an API to initialize and access a COM object.
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.
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.
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.
Outgoing events supported by the COM object are emitted as standard Qt signals.
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
use the QAxBase API like this:
Note that the QList the object should fill has to be provided as an element in the parameter list of QVariant.
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().
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.
A QMap<QString,QVariant> that can store properties as name:value pairs.
QAxBase::QAxBase | ( | IUnknown * | iface = 0 | ) |
Creates a QAxBase object that wraps the COM object iface.
If iface is 0 (the default), use setControl() to instantiate a COM object.
Definition at line 850 of file qaxbase.cpp.
|
virtual |
Shuts down the COM object and destroys the QAxBase object.
Definition at line 868 of file qaxbase.cpp.
QVariant QAxBase::asVariant | ( | ) | const |
Returns a QVariant that wraps the COM object.
The variant can then be used as a parameter in e.g. dynamicCall().
Definition at line 4421 of file qaxbase.cpp.
|
pure virtual |
Implemented in QAxWidget, and QAxObject.
Referenced by MetaObjectGenerator::metaObject().
|
virtual |
Disconnects and destroys the COM object.
If you reimplement this function you must also reimplement the destructor to call clear(), and call this implementation at the end of your clear() function.
Reimplemented in QAxWidget.
Definition at line 1095 of file qaxbase.cpp.
Referenced by QAxWidget::clear(), and QAxObject::~QAxObject().
|
protected |
Connects to all event interfaces of the object.
Called by the subclasses' connectNotify() reimplementations, so at this point the connection as actually been created already.
Definition at line 3282 of file qaxbase.cpp.
Referenced by QAxObject::connectNotify(), QAxWidget::connectNotify(), QAxObject::qObject(), and QAxWidget::qObject().
QString QAxBase::control | ( | ) | const |
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.
The second fastest way is to use the registered control's class name (with or without version number), e.g.
The slowest, but easiest way to use is to use the control's full name, e.g.
It is also possible to initialize the object from a file, e.g.
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:
To initialize a licensed control use the following pattern:
To connect to an already running object use the following pattern:
The first two patterns can be combined, e.g. to initialize a licensed control on a remote machine:
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.
Definition at line 1029 of file qaxbase.cpp.
Referenced by QAxWidget::clear(), operator<<(), operator>>(), qax_generateDocumentation(), qax_noSuchFunction(), and MetaObjectGenerator::readClassInfo().
void QAxBase::disableClassInfo | ( | ) |
Disables the class info generation for this ActiveX container.
If you don't require any class information about the ActiveX control use this function to speed up the meta object generation.
Note that this function must be called immediately after construction of the object
Definition at line 1083 of file qaxbase.cpp.
Referenced by QAxScriptEngine::QAxScriptEngine().
void QAxBase::disableEventSink | ( | ) |
Disables the event sink implementation for this ActiveX container.
If you don't intend to listen to the ActiveX control's events use this function to speed up the meta object generation.
Some ActiveX controls might be unstable when connected to an event sink. To get OLE events you must use standard COM methods to register your own event sink. Use queryInterface() to get access to the raw COM object.
Note that this function should be called immediately after construction of the object.
Definition at line 1047 of file qaxbase.cpp.
Referenced by QAxScriptEngine::QAxScriptEngine().
void QAxBase::disableMetaObject | ( | ) |
Disables the meta object generation for this ActiveX container.
This also disables the event sink and class info generation. If you don't intend to use the Qt meta object implementation call this function to speed up instantiation of the control. You will still be able to call the object through dynamicCall() , but signals, slots and properties will not be available with QObject APIs.
Some ActiveX controls might be unstable when used with OLE automation. Use standard COM methods to use those controls through the COM interfaces provided by queryInterface().
Note that this function must be called immediately after construction of the object.
Definition at line 1068 of file qaxbase.cpp.
QVariant QAxBase::dynamicCall | ( | const char * | function, |
const QVariant & | var1 = QVariant() , |
||
const QVariant & | var2 = QVariant() , |
||
const QVariant & | var3 = QVariant() , |
||
const QVariant & | var4 = QVariant() , |
||
const QVariant & | var5 = QVariant() , |
||
const QVariant & | var6 = QVariant() , |
||
const QVariant & | var7 = QVariant() , |
||
const QVariant & | var8 = QVariant() |
||
) |
Calls the COM object's method function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8, and returns the value returned by the method, or an invalid QVariant if the method does not return a value or when the function call failed.
If function is a method of the object the string must be provided as the full prototype, for example as it would be written in a QObject::connect() call.
Alternatively a function can be called passing the parameters embedded in the string, e.g. above function can also be invoked using
All parameters are passed as strings; it depends on the control whether they are interpreted correctly, and is slower than using the prototype with correctly typed parameters.
If function is a property the string has to be the name of the property. The property setter is called when var1 is a valid QVariant, otherwise the getter is called.
Note that it is faster to get and set properties using QObject::property() and QObject::setProperty().
dynamicCall() can also be used to call objects with a disabled metaobject wrapper, which can improve performance significantely, esp. when calling many different objects of different types during an automation process. ActiveQt will then however not validate parameters.
It is only possible to call functions through dynamicCall() that have parameters or return values of datatypes supported by QVariant. See the QAxBase class documentation for a list of supported and unsupported datatypes. If you want to call functions that have unsupported datatypes in the parameter list, use queryInterface() to retrieve the appropriate COM interface, and use the function directly.
This is also more efficient.
Definition at line 4046 of file qaxbase.cpp.
Referenced by QAxScript::call().
Calls the COM object's method function, passing the parameters in vars, and returns the value returned by the method.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the method does not return a value or when the function call failed this function returns an invalid QVariant object.
The QVariant objects in vars are updated when the method has out-parameters.
Definition at line 4091 of file qaxbase.cpp.
|
private |
name is already normalized?
Definition at line 3784 of file qaxbase.cpp.
|
signal |
This signal is emitted when the COM object throws an exception while called using the OLE automation interface IDispatch.
code, source, desc and help provide information about the exception as provided by the COM server and can be used to provide useful feedback to the end user. help includes the help file, and the help context ID in brackets, e.g. "filename [id]".
|
inline |
Returns a rich text string with documentation for the wrapped COM object.
Dump the string to an HTML-file, or use it in e.g. a QTextBrowser widget.
Definition at line 183 of file qaxbase.h.
|
protected |
Definition at line 1172 of file qaxbase.cpp.
Referenced by QAxObject::doVerb(), and QAxWidget::doVerb().
|
protectedvirtual |
This virtual function is called by setControl() and creates the requested COM object.
ptr is set to the object's IUnknown implementation. The function returns true if the object initialization succeeded; otherwise the function returns false.
The default implementation interprets the string returned by control(), and calls initializeRemote(), initializeLicensed() or initializeActive() if the string matches the respective patterns. If control() is the name of an existing file, initializeFromFile() is called. If no pattern is matched, or if remote or licensed initialization fails, CoCreateInstance is used directly to create the object.
See the control property documentation for details about supported patterns.
The interface returned in ptr must be referenced exactly once when this function returns. The interface provided by e.g. CoCreateInstance is already referenced, and there is no need to reference it again.
Reimplemented in QAxScriptEngine, and QAxWidget.
Definition at line 1199 of file qaxbase.cpp.
Referenced by QAxWidget::initialize().
|
protected |
Connects to an active instance running on the current machine, and returns the IUnknown interface to the running object in ptr.
This function returns true if successful, otherwise returns false.
This function is called by initialize() if the control string contains the substring "}&".
Definition at line 1321 of file qaxbase.cpp.
|
protected |
Used by subclasses generated with dumpcpp to implement cast-operators.
Definition at line 902 of file qaxbase.cpp.
|
protected |
Creates the COM object handling the filename in the control property, and returns the IUnknown interface to the object in ptr.
This function returns true if successful, otherwise returns false.
This function is called by initialize() if the control string is the name of an existing file.
Definition at line 1352 of file qaxbase.cpp.
|
protected |
Creates an instance of a licensed control, and returns the IUnknown interface to the object in ptr.
This functions returns true if successful, otherwise returns false.
This function is called by initialize() if the control string contains the substring "}:". The license key needs to follow this substring.
Definition at line 1240 of file qaxbase.cpp.
|
private |
Definition at line 1261 of file qaxbase.cpp.
|
protected |
Creates the instance on a remote server, and returns the IUnknown interface to the object in ptr.
This function returns true if successful, otherwise returns false.
This function is called by initialize() if the control string contains the substring "/{". The information about the remote machine needs to be provided in front of the substring.
Definition at line 1390 of file qaxbase.cpp.
|
private |
Definition at line 3593 of file qaxbase.cpp.
|
private |
Definition at line 915 of file qaxbase.cpp.
|
private |
Definition at line 3476 of file qaxbase.cpp.
|
protected |
Used by subclasses generated with dumpcpp to balance reference count.
Definition at line 888 of file qaxbase.cpp.
bool QAxBase::isNull | ( | ) | const |
Returns true if there is no COM object loaded by this wrapper; otherwise return false.
Definition at line 4412 of file qaxbase.cpp.
Referenced by QAxWidget::changeEvent(), QAxWidget::clear(), and qax_generateDocumentation().
|
virtual |
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo interface implementations in the COM object.
Reimplemented in QAxWidget, and QAxObject.
Definition at line 3245 of file qaxbase.cpp.
Referenced by checkHRESULT(), QAxObject::metaObject(), QAxWidget::metaObject(), qax_generateDocumentation(), and qax_noSuchFunction().
|
privatepure virtual |
QAxBase::PropertyBag QAxBase::propertyBag | ( | ) | const |
Returns a name:value map of all the properties exposed by the COM object.
This is more efficient than getting multiple properties individually if the COM object supports property bags.
Definition at line 4303 of file qaxbase.cpp.
Referenced by operator<<().
|
signal |
If the COM object supports property notification, this signal gets emitted when the property called name is changed.
|
virtual |
Returns true if the property prop is writable; otherwise returns false.
By default, all properties are writable.
Definition at line 4385 of file qaxbase.cpp.
|
pure virtual |
Implemented in QAxWidget, and QAxObject.
Referenced by checkHRESULT(), operator>>(), and qax_generateDocumentation().
|
virtual |
Reimplemented in QAxWidget, and QAxObject.
Definition at line 3705 of file qaxbase.cpp.
Referenced by checkHRESULT(), QAxObject::qt_metacall(), and QAxWidget::qt_metacall().
long QAxBase::queryInterface | ( | const QUuid & | uuid, |
void ** | iface | ||
) | const |
Requests the interface uuid from the COM object and sets the value of iface to the provided interface, or to 0 if the requested interface could not be provided.
Returns the result of the QueryInterface implementation of the COM object.
Definition at line 1479 of file qaxbase.cpp.
Referenced by QAxClientSite::activateObject(), QAxObject::doVerb(), QAxScriptSite::GetItemInfo(), QAxScriptEngine::hasIntrospection(), QAxHostWidget::paintEvent(), qax_generateDocumentation(), and QVariantToVARIANT().
QAxObject * QAxBase::querySubObject | ( | const char * | name, |
const QVariant & | var1 = QVariant() , |
||
const QVariant & | var2 = QVariant() , |
||
const QVariant & | var3 = QVariant() , |
||
const QVariant & | var4 = QVariant() , |
||
const QVariant & | var5 = QVariant() , |
||
const QVariant & | var6 = QVariant() , |
||
const QVariant & | var7 = QVariant() , |
||
const QVariant & | var8 = QVariant() |
||
) |
Returns a pointer to a QAxObject wrapping the COM object provided by the method or property name, passing passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8.
If name is provided by a method the string must include the full function prototype.
If name is a property the string must be the name of the property, and var1, ... var8 are ignored.
The returned QAxObject is a child of this object (which is either of type QAxObject or QAxWidget), and is deleted when this object is deleted. It is however safe to delete the returned object yourself, and you should do so when you iterate over lists of subobjects.
COM enabled applications usually have an object model publishing certain elements of the application as dispatch interfaces. Use this method to navigate the hierarchy of the object model, e.g.
Definition at line 4130 of file qaxbase.cpp.
The QVariant objects in vars are updated when the method has out-parameters.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 4169 of file qaxbase.cpp.
bool QAxBase::setControl | ( | const QString & | c | ) |
Definition at line 975 of file qaxbase.cpp.
Referenced by operator>>(), QAxObject::QAxObject(), and QAxWidget::QAxWidget().
void QAxBase::setPropertyBag | ( | const PropertyBag & | bag | ) |
Sets the properties of the COM object to the corresponding values in bag.
Definition at line 4347 of file qaxbase.cpp.
Referenced by operator>>().
|
virtual |
Sets the property prop to writable if ok is true, otherwise sets prop to be read-only.
By default, all properties are writable.
Definition at line 4401 of file qaxbase.cpp.
|
signal |
This generic signal gets emitted when the COM object issues the event name.
argc is the number of parameters provided by the event (DISPPARAMS.cArgs), and argv is the pointer to the parameter values (DISPPARAMS.rgvarg). Note that the order of parameter values is turned around, ie. the last element of the array is the first parameter in the function.
Use this signal if the event has parameters of unsupported data types. Otherwise, connect directly to the signal name.
Referenced by QAxObject::qObject(), and QAxWidget::qObject().
QStringList QAxBase::verbs | ( | ) | const |
Returns the list of verbs that the COM object can execute.
If the object does not implement IOleObject, or does not support any verbs, then this function returns an empty stringlist.
Note that the OLE default verbs (OLEIVERB_SHOW etc) are not included in the list.
Definition at line 1137 of file qaxbase.cpp.
Referenced by QAxObject::doVerb(), and QAxWidget::doVerb().
|
friend |
Definition at line 4448 of file qaxbase.cpp.
|
friend |
|
private |
Definition at line 150 of file qaxbase.h.
Referenced by initializeFrom().
|
staticprivate |