Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QAxBase Class

TheQAxBase class is an abstract class that provides an API to initialize and access a COM object.More...

Header:#include <QAxBase>
Inherited By:

QAxObject andQAxWidget

Public Types

typedefPropertyBag

Properties

Public Functions

QAxBase(IUnknown * iface = 0)
virtual~QAxBase()
QVariantasVariant() const
virtual voidclear()
QStringcontrol() const
voiddisableClassInfo()
voiddisableEventSink()
voiddisableMetaObject()
QVariantdynamicCall(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())
QVariantdynamicCall(const char * function, QList<QVariant> & vars)
QStringgenerateDocumentation()
boolisNull() const
PropertyBagpropertyBag() const
virtual boolpropertyWritable(const char * prop) const
longqueryInterface(const QUuid & uuid, void ** iface) const
QAxObject *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())
QAxObject *querySubObject(const char * name, QList<QVariant> & vars)
boolsetControl(const QString &)
voidsetPropertyBag(const PropertyBag & bag)
virtual voidsetPropertyWritable(const char * prop, bool ok)
QStringListverbs() const

Signals

voidexception(int code, const QString & source, const QString & desc, const QString & help)
voidpropertyChanged(const QString & name)
voidsignal(const QString & name, int argc, void * argv)

Protected Functions

virtual boolinitialize(IUnknown ** ptr)
boolinitializeActive(IUnknown ** ptr)
boolinitializeFromFile(IUnknown ** ptr)
boolinitializeLicensed(IUnknown ** ptr)
boolinitializeRemote(IUnknown ** ptr)

Detailed Description

TheQAxBase 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 subclassesQAxObject andQAxWidget. 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 areQObjects, so you can useQObject::setProperty() andQObject::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 usingdynamicCall(), 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 theQObject 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 typeQt propertyin-parameterout-parameter
VARIANT_BOOLboolboolbool&
BSTRQStringconstQString&QString&
char, short, int, longintintint&
uchar, ushort, uint, ulonguintuintuint&
float, doubledoubledoubledouble&
DATEQDateTimeconstQDateTime&QDateTime&
CYqlonglongqlonglongqlonglong&
OLE_COLORQColorconstQColor&QColor&
SAFEARRAY(VARIANT)QList<QVariant>constQList<QVariant>&QList<QVariant>&
SAFEARRAY(int), SAFEARRAY(double), SAFEARRAY(Date)QList<QVariant>constQList<QVariant>&QList<QVariant>&
SAFEARRAY(BYTE)QByteArrayconstQByteArray&QByteArray&
SAFEARRAY(BSTR)QStringListconstQStringList&QStringList&
VARIANTtype-dependentconstQVariant&QVariant&
IFontDisp*QFontconstQFont&QFont&
IPictureDisp*QPixmapconstQPixmap&QPixmap&
IDispatch*QAxObject*QAxBase::asVariant()QAxObject* (return value)
IUnknown*QAxObject*QAxBase::asVariant()QAxObject* (return value)
SCODE, DECIMALunsupportedunsupportedunsupported
VARIANT* (Since Qt 4.5)unsupportedQVariant&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 theQAxBase 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 theQList the object should fill has to be provided as an element in the parameter list ofQVariants.

If you need to access properties or pass parameters of unsupported datatypes you must access the COM object directly through itsIDispatch implementation or other interfaces. Those interfaces can be retrieved throughqueryInterface().

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 alsoQAxObject,QAxWidget,QAxScript, andActiveQt Framework.

Member Type Documentation

typedef QAxBase::PropertyBag

AQMap<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:

QStringcontrol() const
boolsetControl(const QString &)

Member Function Documentation

QAxBase::QAxBase(IUnknown * iface = 0)

Creates aQAxBase object that wraps the COM objectiface. Ififace is 0 (the default), usesetControl() to instantiate a COM object.

[virtual]QAxBase::~QAxBase()

Shuts down the COM object and destroys theQAxBase object.

See alsoclear().

QVariant QAxBase::asVariant() const

Returns aQVariant that wraps the COM object. The variant can then be used as a parameter in e.g.dynamicCall().

[virtual]void QAxBase::clear()

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.

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

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. UsequeryInterface() to get access to the raw COM object.

Note that this function should be called immediately after construction of the object.

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 throughdynamicCall(), but signals, slots and properties will not be available withQObject 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 byqueryInterface().

Note that this function must be called immediately after construction of the object.

QVariant QAxBase::dynamicCall(constchar * function, constQVariant & var1 = QVariant(), constQVariant & var2 = QVariant(), constQVariant & var3 = QVariant(), constQVariant & var4 = QVariant(), constQVariant & var5 = QVariant(), constQVariant & var6 = QVariant(), constQVariant & var7 = QVariant(), constQVariant & var8 = QVariant())

Calls the COM object's methodfunction, passing the parametersvar1,var1,var2,var3,var4,var5,var6,var7 andvar8, and returns the value returned by the method, or an invalidQVariant if the method does not return a value or when the function call failed.

Iffunction is a method of the object the string must be provided as the full prototype, for example as it would be written in aQObject::connect() call.

activeX->dynamicCall("Navigate(const QString&)","www.qt-project.org");

Alternatively a function can be called passing the parameters embedded in the string, e.g. above function can also be invoked using

activeX->dynamicCall("Navigate(\"www.qt-project.org\")");

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.

Iffunction is a property the string has to be the name of the property. The property setter is called whenvar1 is a validQVariant, otherwise the getter is called.

activeX->dynamicCall("Value",5);QString text= activeX->dynamicCall("Text").toString();

Note that it is faster to get and set properties usingQObject::property() andQObject::setProperty().

dynamicCall() can also be used to call objects with adisabled 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 byQVariant. See theQAxBase class documentation for a list of supported and unsupported datatypes. If you want to call functions that have unsupported datatypes in the parameter list, usequeryInterface() to retrieve the appropriate COM interface, and use the function directly.

IWebBrowser2*webBrowser=0;activeX->queryInterface(IID_IWebBrowser2, (void**)&webBrowser);if (webBrowser) {    webBrowser->Navigate2(pvarURL);    webBrowser->Release();}

This is also more efficient.

QVariant QAxBase::dynamicCall(constchar * function,QList<QVariant> & vars)

This is an overloaded function.

Calls the COM object's methodfunction, passing the parameters invars, and returns the value returned by the method. If the method does not return a value or when the function call failed this function returns an invalidQVariant object.

TheQVariant objects invars are updated when the method has out-parameters.

[signal]void QAxBase::exception(int code, constQString & source, constQString & desc, constQString & help)

This signal is emitted when the COM object throws an exception while called using the OLE automation interface IDispatch.code,source,desc andhelp 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]".

QString QAxBase::generateDocumentation()

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. aQTextBrowser widget.

[virtual protected]bool QAxBase::initialize(IUnknown ** ptr)

This virtual function is called bysetControl() 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 bycontrol(), and callsinitializeRemote(),initializeLicensed() orinitializeActive() if the string matches the respective patterns. Ifcontrol() 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 thecontrol property documentation for details about supported patterns.

The interface returned inptr 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.

[protected]bool QAxBase::initializeActive(IUnknown ** ptr)

Connects to an active instance running on the current machine, and returns the IUnknown interface to the running object inptr. This function returns true if successful, otherwise returns false.

This function is called byinitialize() if the control string contains the substring "}&".

See alsoinitialize().

[protected]bool QAxBase::initializeFromFile(IUnknown ** ptr)

Creates the COM object handling the filename in the control property, and returns the IUnknown interface to the object inptr. This function returns true if successful, otherwise returns false.

This function is called byinitialize() if the control string is the name of an existing file.

See alsoinitialize().

[protected]bool QAxBase::initializeLicensed(IUnknown ** ptr)

Creates an instance of a licensed control, and returns the IUnknown interface to the object inptr. This functions returns true if successful, otherwise returns false.

This function is called byinitialize() if the control string contains the substring "}:". The license key needs to follow this substring.

See alsoinitialize().

[protected]bool QAxBase::initializeRemote(IUnknown ** ptr)

Creates the instance on a remote server, and returns the IUnknown interface to the object inptr. This function returns true if successful, otherwise returns false.

This function is called byinitialize() if the control string contains the substring "/{". The information about the remote machine needs to be provided in front of the substring.

See alsoinitialize().

bool QAxBase::isNull() const

Returns true if there is no COM object loaded by this wrapper; otherwise return false.

See alsocontrol.

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.

Warning: It is not guaranteed that the property bag implementation of the COM object returns all properties, or that the properties returned are the same as those available through the IDispatch interface.

See alsosetPropertyBag().

[signal]void QAxBase::propertyChanged(constQString & name)

If the COM object supports property notification, this signal gets emitted when the property calledname is changed.

[virtual]bool QAxBase::propertyWritable(constchar * prop) const

Returns true if the propertyprop is writable; otherwise returns false. By default, all properties are writable.

Warning: Depending on the control implementation this setting might be ignored for some properties.

See alsosetPropertyWritable() andpropertyChanged().

long QAxBase::queryInterface(constQUuid & uuid,void ** iface) const

Requests the interfaceuuid from the COM object and sets the value ofiface 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.

See alsocontrol.

QAxObject * QAxBase::querySubObject(constchar * name, constQVariant & var1 = QVariant(), constQVariant & var2 = QVariant(), constQVariant & var3 = QVariant(), constQVariant & var4 = QVariant(), constQVariant & var5 = QVariant(), constQVariant & var6 = QVariant(), constQVariant & var7 = QVariant(), constQVariant & var8 = QVariant())

Returns a pointer to aQAxObject wrapping the COM object provided by the method or propertyname, passing passing the parametersvar1,var1,var2,var3,var4,var5,var6,var7 andvar8.

Ifname is provided by a method the string must include the full function prototype.

Ifname is a property the string must be the name of the property, andvar1, ...var8 are ignored.

The returnedQAxObject is a child of this object (which is either of typeQAxObject orQAxWidget), 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.

QAxWidget outlook("Outlook.Application");QAxObject*session= outlook.querySubObject("Session");if (session) {QAxObject*defFolder= session->querySubObject("GetDefaultFolder(OlDefaultFolders)","olFolderContacts");//...}

QAxObject * QAxBase::querySubObject(constchar * name,QList<QVariant> & vars)

This is an overloaded function.

TheQVariant objects invars are updated when the method has out-parameters.

void QAxBase::setPropertyBag(constPropertyBag & bag)

Sets the properties of the COM object to the corresponding values inbag.

Warning: You should only set property bags that have been returned by thepropertyBag function, as it cannot be guaranteed that the property bag implementation of the COM object supports the same properties that are available through the IDispatch interface.

See alsopropertyBag().

[virtual]void QAxBase::setPropertyWritable(constchar * prop,bool ok)

Sets the propertyprop to writable ifok is true, otherwise setsprop to be read-only. By default, all properties are writable.

Warning: Depending on the control implementation this setting might be ignored for some properties.

See alsopropertyWritable() andpropertyChanged().

[signal]void QAxBase::signal(constQString & name,int argc,void * argv)

This generic signal gets emitted when the COM object issues the eventname.argc is the number of parameters provided by the event (DISPPARAMS.cArgs), andargv 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.

void Receiver::slot(constQString&name,int argc,void*argv){    VARIANTARG*params= (VARIANTARG*)argv;if (name.startsWith("BeforeNavigate2(")) {        IDispatch*pDisp= params[argc-1].pdispVal;        VARIANTARG URL=*params[argc-2].pvarVal;        VARIANTARG Flags=*params[argc-3].pvarVal;        VARIANTARG TargetFrameName=*params[argc-4].pvarVal;        VARIANTARG PostData=*params[argc-5].pvarVal;        VARIANTARG Headers=*params[argc-6].pvarVal;        bool*Cancel= params[argc-7].pboolVal;    }}

Use this signal if the event has parameters of unsupported data types. Otherwise, connect directly to the signalname.

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.

This function was introduced in Qt 4.1.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp