Qt 4.8
Public Types | Signals | Public Functions | Protected Functions | Private Functions | Properties | Static Private Attributes | Friends | List of all members
QAxBase Class Referenceabstract

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

#include <qaxbase.h>

Inheritance diagram for QAxBase:
QAxObject QAxWidget QAxScriptEngine

Public Types

typedef QMap< QString, QVariantPropertyBag
 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 QMetaObjectmetaObject () 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 QObjectqObject () 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...
 
QAxObjectquerySubObject (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...
 
QAxObjectquerySubObject (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)
 
QAxMetaObjectinternalMetaObject () const
 
int internalProperty (QMetaObject::Call, int index, void **v)
 
virtual const QMetaObjectparentMetaObject () const =0
 

Properties

QAxBasePrivated
 

Static Private Attributes

static QMetaObject staticMetaObject
 

Friends

void * qax_createObjectWrapper (int, IUnknown *)
 
class QAxEventSink
 

Detailed Description

The QAxBase class is an abstract class that provides an API to initialize and access a COM object.

Attention
Module: QAxContainer

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
{
[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> 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 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().

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, {ActiveQt Framework}

Definition at line 66 of file qaxbase.h.

Typedefs

◆ PropertyBag

A QMap<QString,QVariant> that can store properties as name:value pairs.

Definition at line 71 of file qaxbase.h.

Constructors and Destructors

◆ QAxBase()

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.

851 {
852  d = new QAxBasePrivate();
853  d->ptr = iface;
854  if (d->ptr) {
855  d->ptr->AddRef();
856  d->initialized = true;
857  }
858 #if defined(Q_OS_WINCE)
859  CoInitializeEx(0, COINIT_MULTITHREADED);
860 #endif
861 }
IUnknown * ptr
Definition: qaxbase.cpp:600
QAxBasePrivate * d
Definition: qaxbase.h:150
uint initialized
Definition: qaxbase.cpp:597

◆ ~QAxBase()

QAxBase::~QAxBase ( )
virtual

Shuts down the COM object and destroys the QAxBase object.

See also
clear()

Definition at line 868 of file qaxbase.cpp.

869 {
870 #if defined(Q_OS_WINCE)
871  CoUninitialize();
872 #endif
873 
874  clear();
875 
876  delete d;
877  d = 0;
878 }
QAxBasePrivate * d
Definition: qaxbase.h:150
virtual void clear()
Disconnects and destroys the COM object.
Definition: qaxbase.cpp:1095

Functions

◆ asVariant()

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.

4422 {
4423  if (!d->ptr && !d->initialized) {
4424  ((QAxBase*)this)->initialize(&d->ptr);
4425  d->initialized = true;
4426  }
4427 
4428  QVariant qvar;
4429  QByteArray cn(className());
4430  if (cn == "QAxObject" || cn == "QAxWidget" || cn == "QAxBase") {
4431  if (d->dispatch())
4432  qvar.setValue(d->dispatch());
4433  else if (d->ptr)
4434  qvar.setValue(d->ptr);
4435  } else {
4436  cn = cn.mid(cn.lastIndexOf(':') + 1);
4437  QObject *object = qObject();
4438  if (QMetaType::type(cn))
4439  qvar = QVariant(qRegisterMetaType<QObject*>(cn + '*'), &object);
4440 // qvar.setValue(qObject(), cn + '*');
4441  }
4442 
4443  return qvar;
4444 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
IUnknown * ptr
Definition: qaxbase.cpp:600
virtual QObject * qObject() const =0
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setValue(const T &value)
Stores a copy of value.
Definition: qvariant.h:527
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual const char * className() const =0
QAxBasePrivate * d
Definition: qaxbase.h:150
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
uint initialized
Definition: qaxbase.cpp:597
IDispatch * dispatch() const
Definition: qaxbase.cpp:580
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
Definition: qaxbase.h:66

◆ className()

const char * QAxBase::className ( ) const
pure virtual
Warning
This function is not part of the public interface.

Implemented in QAxWidget, and QAxObject.

Referenced by MetaObjectGenerator::metaObject().

◆ clear()

void QAxBase::clear ( )
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().

1096 {
1098  while (it != d->eventSink.end()) {
1099  QAxEventSink *eventSink = it.value();
1100  ++it;
1101  if (eventSink) {
1102  eventSink->unadvise();
1103  eventSink->Release();
1104  }
1105  }
1106  d->eventSink.clear();
1107  if (d->disp) {
1108  d->disp->Release();
1109  d->disp = 0;
1110  }
1111  if (d->ptr) {
1112  d->ptr->Release();
1113  d->ptr = 0;
1114  d->initialized = false;
1115  }
1116 
1117  d->ctrl.clear();
1118 
1119  if (!d->cachedMetaObject)
1120  delete d->metaobj;
1121  d->metaobj = 0;
1122 }
IUnknown * ptr
Definition: qaxbase.cpp:600
void clear()
Removes all items from the hash.
Definition: qhash.h:574
#define it(className, varName)
QAxMetaObject * metaobj
Definition: qaxbase.cpp:614
unsigned long __stdcall Release()
Definition: qaxbase.cpp:295
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
QHash< QUuid, QAxEventSink * > eventSink
Definition: qaxbase.cpp:592
QString ctrl
Definition: qaxbase.cpp:590
QAxBasePrivate * d
Definition: qaxbase.h:150
uint cachedMetaObject
Definition: qaxbase.cpp:596
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
uint initialized
Definition: qaxbase.cpp:597
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
IDispatch * disp
Definition: qaxbase.cpp:601
void unadvise()
Definition: qaxbase.cpp:249

◆ connectNotify()

void QAxBase::connectNotify ( )
protected

Connects to all event interfaces of the object.

Warning
This function is not part of the public interface.

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().

3283 {
3284  if (d->eventSink.count()) // already listening
3285  return;
3286 
3287  IEnumConnectionPoints *epoints = 0;
3288  if (d->ptr && d->useEventSink) {
3289  IConnectionPointContainer *cpoints = 0;
3290  d->ptr->QueryInterface(IID_IConnectionPointContainer, (void**)&cpoints);
3291  if (!cpoints)
3292  return;
3293 
3294  cpoints->EnumConnectionPoints(&epoints);
3295  cpoints->Release();
3296  }
3297 
3298  if (!epoints)
3299  return;
3300 
3301  UINT index;
3302  IDispatch *disp = d->dispatch();
3303  ITypeInfo *typeinfo = 0;
3304  ITypeLib *typelib = 0;
3305  if (disp)
3306  disp->GetTypeInfo(0, LOCALE_USER_DEFAULT, &typeinfo);
3307  if (typeinfo)
3308  typeinfo->GetContainingTypeLib(&typelib, &index);
3309 
3310  if (!typelib) {
3311  epoints->Release();
3312  return;
3313  }
3314 
3315  MetaObjectGenerator generator(this, d);
3316  bool haveEnumInfo = false;
3317 
3318  ULONG c = 1;
3319  IConnectionPoint *cpoint = 0;
3320  epoints->Reset();
3321  do {
3322  if (cpoint) cpoint->Release();
3323  cpoint = 0;
3324  epoints->Next(c, &cpoint, &c);
3325  if (!c || !cpoint)
3326  break;
3327 
3328  IID conniid;
3329  cpoint->GetConnectionInterface(&conniid);
3330  // workaround for typelibrary bug of Word.Application
3331  QString connuuid(QUuid(conniid).toString());
3332  if (d->eventSink.contains(connuuid))
3333  break;
3334 
3335  // Get ITypeInfo for source-interface, and skip if not supporting IDispatch
3336  ITypeInfo *eventinfo = 0;
3337  typelib->GetTypeInfoOfGuid(conniid, &eventinfo);
3338  if (eventinfo) {
3339  TYPEATTR *eventAttr;
3340  eventinfo->GetTypeAttr(&eventAttr);
3341  if (!eventAttr) {
3342  eventinfo->Release();
3343  break;
3344  }
3345 
3346  TYPEKIND eventKind = eventAttr->typekind;
3347  eventinfo->ReleaseTypeAttr(eventAttr);
3348  if (eventKind != TKIND_DISPATCH) {
3349  eventinfo->Release();
3350  break;
3351  }
3352  }
3353 
3354  // always into the cache to avoid recoursion
3355  QAxEventSink *eventSink = eventinfo ? new QAxEventSink(this) : 0;
3356  d->eventSink.insert(connuuid, eventSink);
3357 
3358  if (!eventinfo)
3359  continue;
3360 
3361  // have to get type info to support signals with enum parameters
3362  if (!haveEnumInfo) {
3363  bool wasTryCache = d->tryCache;
3364  d->tryCache = true;
3365  generator.readClassInfo();
3366  generator.readEnumInfo();
3367  d->tryCache = wasTryCache;
3368  haveEnumInfo = true;
3369  }
3370  generator.readEventInterface(eventinfo, cpoint);
3371  eventSink->advise(cpoint, conniid);
3372 
3373  eventinfo->Release();
3374  } while (c);
3375  if (cpoint) cpoint->Release();
3376  epoints->Release();
3377 
3378  typelib->Release();
3379 
3380  // make sure we don't try again
3381  if (!d->eventSink.count())
3382  d->eventSink.insert(QString(), 0);
3383 }
IUnknown * ptr
Definition: qaxbase.cpp:600
unsigned char c[8]
Definition: qnumeric_p.h:62
void advise(IConnectionPoint *cp, IID iid)
Definition: qaxbase.cpp:240
The QString class provides a Unicode character string.
Definition: qstring.h:83
friend class QAxEventSink
Definition: qaxbase.h:147
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QHash< QUuid, QAxEventSink * > eventSink
Definition: qaxbase.cpp:592
static QString toString(Register *reg, int type, bool *ok=0)
QAxBasePrivate * d
Definition: qaxbase.h:150
uint useEventSink
Definition: qaxbase.cpp:593
quint16 index
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
IDispatch * dispatch() const
Definition: qaxbase.cpp:580
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67

◆ control()

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.

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.

Definition at line 1029 of file qaxbase.cpp.

Referenced by QAxWidget::clear(), operator<<(), operator>>(), qax_generateDocumentation(), qax_noSuchFunction(), and MetaObjectGenerator::readClassInfo().

1030 {
1031  return d->ctrl;
1032 }
QString ctrl
Definition: qaxbase.cpp:590
QAxBasePrivate * d
Definition: qaxbase.h:150

◆ disableClassInfo()

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().

1084 {
1085  d->useClassInfo = false;
1086 }
QAxBasePrivate * d
Definition: qaxbase.h:150
uint useClassInfo
Definition: qaxbase.cpp:595

◆ disableEventSink()

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().

1048 {
1049  d->useEventSink = false;
1050 }
QAxBasePrivate * d
Definition: qaxbase.h:150
uint useEventSink
Definition: qaxbase.cpp:593

◆ disableMetaObject()

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.

1069 {
1070  d->useMetaObject = false;
1071  d->useEventSink = false;
1072  d->useClassInfo = false;
1073 }
QAxBasePrivate * d
Definition: qaxbase.h:150
uint useEventSink
Definition: qaxbase.cpp:593
uint useClassInfo
Definition: qaxbase.cpp:595
uint useMetaObject
Definition: qaxbase.cpp:594

◆ dynamicCall() [1/2]

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.

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.

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.

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

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.

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

This is also more efficient.

Definition at line 4046 of file qaxbase.cpp.

Referenced by QAxScript::call().

4055 {
4056  QList<QVariant> vars;
4057  QVariant var = var1;
4058  int argc = 1;
4059  while(var.isValid()) {
4060  vars << var;
4061  switch(++argc) {
4062  case 2: var = var2; break;
4063  case 3: var = var3; break;
4064  case 4: var = var4; break;
4065  case 5: var = var5; break;
4066  case 6: var = var6; break;
4067  case 7: var = var7; break;
4068  case 8: var = var8; break;
4069  default:var = QVariant(); break;
4070  }
4071  }
4072 
4073  return dynamicCall(function, vars);
4074 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
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&#39;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.
Definition: qaxbase.cpp:4046
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ dynamicCall() [2/2]

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

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.

4092 {
4093  VARIANTARG res;
4094  VariantInit(&res);
4095 
4096  QByteArray rettype;
4097  if (!dynamicCallHelper(function, &res, vars, rettype))
4098  return QVariant();
4099 
4100  QVariant qvar = VARIANTToQVariant(res, rettype);
4101  if ((res.vt != VT_DISPATCH && res.vt != VT_UNKNOWN) || qvar.type() == QVariant::Pixmap || qvar.type() == QVariant::Font)
4102  clearVARIANT(&res);
4103 
4104  return qvar;
4105 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void clearVARIANT(VARIANT *var)
Definition: qaxtypes.cpp:1408
bool dynamicCallHelper(const char *name, void *out, QList< QVariant > &var, QByteArray &type)
Definition: qaxbase.cpp:3784
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
Returns arg as a QVariant of type type.
Definition: qaxtypes.cpp:919

◆ dynamicCallHelper()

bool QAxBase::dynamicCallHelper ( const char *  name,
void *  inout,
QList< QVariant > &  vars,
QByteArray type 
)
private
Warning
This function is not part of the public interface.

name is already normalized?

Definition at line 3784 of file qaxbase.cpp.

3785 {
3786  if (isNull()) {
3787  qWarning("QAxBase::dynamicCallHelper: Object is not initialized, or initialization failed");
3788  return false;
3789  }
3790 
3791  IDispatch *disp = d->dispatch();
3792  if (!disp) {
3793  qWarning("QAxBase::dynamicCallHelper: Object does not support automation");
3794  return false;
3795  }
3796 
3797  const QMetaObject *mo = metaObject();
3798  d->metaObject();
3799  Q_ASSERT(d->metaobj);
3800 
3801  int varc = vars.count();
3802 
3804  QByteArray function(normFunction);
3805  VARIANT staticarg[QAX_NUM_PARAMS];
3806  VARIANT *arg = 0;
3807  VARIANTARG *res = (VARIANTARG*)inout;
3808 
3809  unsigned short disptype;
3810 
3811  int id = -1;
3812  bool parse = false;
3813 
3814  if (function.contains('(')) {
3815  disptype = DISPATCH_METHOD | DISPATCH_PROPERTYGET;
3816  if (d->useMetaObject)
3817  id = mo->indexOfSlot(function);
3818  if (id >= 0) {
3819  const QMetaMethod slot = mo->method(id);
3821  function = slot.signature();
3822  type = slot.typeName();
3823  }
3824  function.truncate(function.indexOf('('));
3825  parse = !varc && normFunction.length() > function.length() + 2;
3826  if (parse) {
3827  QString args = QLatin1String(normFunction);
3828  args = args.mid(function.length() + 1);
3829  // parse argument string int list of arguments
3830  QString curArg;
3831  const QChar *c = args.unicode();
3832  int index = 0;
3833  bool inString = false;
3834  bool inEscape = false;
3835  while (index < (int)args.length()) {
3836  QChar cc = *c;
3837  ++c;
3838  ++index;
3839  switch(cc.toLatin1()) {
3840  case 'n':
3841  if (inEscape)
3842  cc = QLatin1Char('\n');
3843  break;
3844  case 'r':
3845  if (inEscape)
3846  cc = QLatin1Char('\r');
3847  break;
3848  case 't':
3849  if (inEscape)
3850  cc = QLatin1Char('\t');
3851  break;
3852  case '\\':
3853  if (!inEscape && inString) {
3854  inEscape = true;
3855  continue;
3856  }
3857  break;
3858  case '"':
3859  if (!inEscape) {
3860  inString = !inString;
3861  curArg += cc;
3862  continue;
3863  }
3864  break;
3865  case ' ':
3866  if (!inString && curArg.isEmpty())
3867  continue;
3868  break;
3869  case ',':
3870  case ')':
3871  if (inString)
3872  break;
3873  curArg = curArg.trimmed();
3874  if (curArg.at(0) == QLatin1Char('\"') && curArg.at(curArg.length()-1) == QLatin1Char('\"')) {
3875  vars << curArg.mid(1, curArg.length() - 2);
3876  } else {
3877  bool isNumber = false;
3878  bool isDouble = false;
3879  int number = curArg.toInt(&isNumber);
3880  double dbl = curArg.toDouble(&isDouble);
3881  if (isNumber) {
3882  vars << number;
3883  } else if (isDouble) {
3884  vars << dbl;
3885  } else {
3886  bool isEnum = false;
3887  for (int enumIndex = 0; enumIndex < mo->enumeratorCount(); ++enumIndex) {
3888  QMetaEnum metaEnum =mo->enumerator(enumIndex);
3889  int value = metaEnum.keyToValue(curArg.toLatin1());
3890  if (value != -1 && !QByteArray(metaEnum.valueToKey(value)).isEmpty()) {
3891  vars << value;
3892  isEnum = true;
3893  break;
3894  }
3895  }
3896  if (!isEnum)
3897  vars << curArg;
3898  }
3899  }
3900  curArg.clear();
3901  continue;
3902  default:
3903  break;
3904  }
3905  inEscape = false;
3906  curArg += cc;
3907  }
3908 
3909  varc = vars.count();
3910  }
3911  } else {
3912  if (d->useMetaObject)
3913  id = mo->indexOfProperty(normFunction);
3914 
3915  if (id >= 0) {
3916  const QMetaProperty prop =mo->property(id);
3917  type = prop.typeName();
3918  }
3919  if (varc == 1) {
3920  res = 0;
3921  disptype = DISPATCH_PROPERTYPUT;
3922  } else {
3923  disptype = DISPATCH_PROPERTYGET;
3924  }
3925  }
3926  if (varc) {
3927  varc = qMin(varc, d->metaobj->numParameter(normFunction));
3928  arg = varc <= QAX_NUM_PARAMS ? staticarg : new VARIANT[varc];
3929  for (int i = 0; i < varc; ++i) {
3930  QVariant var(vars.at(i));
3931  VariantInit(arg + (varc - i - 1));
3932  bool out = false;
3934  if (disptype == DISPATCH_PROPERTYPUT)
3935  paramType = type;
3936  else if (parse || disptype == DISPATCH_PROPERTYGET)
3937  paramType = 0;
3938  else
3939  paramType = d->metaobj->paramType(normFunction, i, &out);
3940 
3941  if ((!parse && d->useMetaObject && var.type() == QVariant::String) || var.type() == QVariant::ByteArray) {
3942  int enumIndex =mo->indexOfEnumerator(paramType);
3943  if (enumIndex != -1) {
3944  QMetaEnum metaEnum =mo->enumerator(enumIndex);
3945  QVariantToVARIANT(metaEnum.keyToValue(var.toByteArray()), arg[varc - i - 1], "int", out);
3946  }
3947  }
3948 
3949  if (arg[varc - i - 1].vt == VT_EMPTY)
3950  QVariantToVARIANT(var, arg[varc - i - 1], paramType, out);
3951  }
3952  }
3953 
3954  DISPID dispid = d->metaobj->dispIDofName(function, disp);
3955  if (dispid == DISPID_UNKNOWN && function.toLower().startsWith("set")) {
3956  function = function.mid(3);
3957  dispid = d->metaobj->dispIDofName(function, disp);
3958  disptype = DISPATCH_PROPERTYPUT;
3959  }
3960 
3961  if (dispid == DISPID_UNKNOWN) {
3962 #ifdef QT_CHECK_STATE
3963  qax_noSuchFunction(disptype, normFunction, function, this);
3964 #endif
3965  return false;
3966  }
3967 
3968  DISPPARAMS params;
3969  DISPID dispidNamed = DISPID_PROPERTYPUT;
3970 
3971  params.cArgs = varc;
3972  params.cNamedArgs = (disptype == DISPATCH_PROPERTYPUT) ? 1 : 0;
3973  params.rgdispidNamedArgs = (disptype == DISPATCH_PROPERTYPUT) ? &dispidNamed : 0;
3974  params.rgvarg = arg;
3975  EXCEPINFO excepinfo;
3976  memset(&excepinfo, 0, sizeof(excepinfo));
3977  UINT argerr = 0;
3978 
3979  HRESULT hres = disp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, disptype, &params, res, &excepinfo, &argerr);
3980 
3981  if (disptype == (DISPATCH_METHOD|DISPATCH_PROPERTYGET) && hres == S_OK && varc) {
3982  for (int i = 0; i < varc; ++i)
3983  if (arg[varc-i-1].vt & VT_BYREF) // update out-parameters
3984  vars[i] = VARIANTToQVariant(arg[varc-i-1], vars.at(i).typeName());
3985  }
3986 
3987  // clean up
3988  for (int i = 0; i < varc; ++i)
3989  clearVARIANT(params.rgvarg+i);
3990  if (arg && arg != staticarg)
3991  delete[] arg;
3992 
3993  return checkHRESULT(hres, &excepinfo, this, QLatin1String(function), varc-argerr-1);
3994 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void clearVARIANT(VARIANT *var)
Definition: qaxtypes.cpp:1408
bool isNull() const
Returns true if there is no COM object loaded by this wrapper; otherwise return false.
Definition: qaxbase.cpp:4412
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
#define QAX_NUM_PARAMS
Definition: qaxtypes.h:74
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
QAxMetaObject * metaobj
Definition: qaxbase.cpp:614
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static void qax_noSuchFunction(int disptype, const QByteArray &name, const QByteArray &function, const QAxBase *that)
Definition: qaxbase.cpp:3748
const char * valueToKey(int value) const
Returns the string that is used as the name of the given enumeration value, or 0 if value is not defi...
static bool checkHRESULT(HRESULT hres, EXCEPINFO *exc, QAxBase *that, const QString &name, uint argerr)
Definition: qaxbase.cpp:3396
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool isNumber(char s)
int numParameter(const QByteArray &prototype)
Definition: qaxbase.cpp:134
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static bool isEmpty(const char *str)
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QAxBasePrivate * d
Definition: qaxbase.h:150
bool QVariantToVARIANT(const QVariant &var, VARIANT &arg, const QByteArray &typeName, bool out)
Definition: qaxtypes.cpp:246
Q_CORE_EXPORT void qWarning(const char *,...)
int enumeratorCount() const
Returns the number of enumerators in this class.
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QByteArray paramType(const QByteArray &signature, int index, bool *out=0)
Definition: qaxbase.cpp:142
int length() const
Same as size().
Definition: qbytearray.h:356
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
long HRESULT
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QByteArray paramType(const QByteArray &ptype, bool *out)
double toDouble(bool *ok=0) const
Returns the string converted to a double value.
Definition: qstring.cpp:6227
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
Returns arg as a QVariant of type type.
Definition: qaxtypes.cpp:919
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int keyToValue(const char *key) const
Returns the integer value of the given enumeration key, or -1 if key is not defined.
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376
quint16 index
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
DISPID dispIDofName(const QByteArray &name, IDispatch *disp)
Definition: qaxbase.cpp:168
QAxMetaObject * metaObject()
Definition: qaxbase.cpp:605
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
int indexOfEnumerator(const char *name) const
Finds enumerator name and returns its index; otherwise returns -1.
IDispatch * dispatch() const
Definition: qaxbase.cpp:580
const char * typeName() const
Returns the name of this property&#39;s type.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
uint useMetaObject
Definition: qaxbase.cpp:594
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ exception

void QAxBase::exception ( int  code,
const QString source,
const QString desc,
const QString help 
)
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]".

◆ generateDocumentation()

QString QAxBase::generateDocumentation ( )
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.

184 {
185  return qax_generateDocumentation(this);
186 }
QString qax_generateDocumentation(QAxBase *)
Definition: qaxdump.cpp:130

◆ indexOfVerb()

long QAxBase::indexOfVerb ( const QString verb) const
protected
Warning
This function is not part of the public interface.

Definition at line 1172 of file qaxbase.cpp.

Referenced by QAxObject::doVerb(), and QAxWidget::doVerb().

1173 {
1174  return d->verbs.value(verb);
1175 }
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
QAxBasePrivate * d
Definition: qaxbase.h:150
QMap< QString, LONG > verbs
Definition: qaxbase.cpp:612

◆ initialize()

bool QAxBase::initialize ( IUnknown **  ptr)
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().

1200 {
1201  if (*ptr || control().isEmpty())
1202  return false;
1203 
1204  *ptr = 0;
1205 
1206  bool res = false;
1207 
1208  const QString ctrl(d->ctrl);
1209  if (ctrl.contains(QLatin1String("/{"))) // DCOM request
1210  res = initializeRemote(ptr);
1211  else if (ctrl.contains(QLatin1String("}:"))) // licensed control
1212  res = initializeLicensed(ptr);
1213  else if (ctrl.contains(QLatin1String("}&"))) // running object
1214  res = initializeActive(ptr);
1215  else if (QFile::exists(ctrl)) // existing file
1216  res = initializeFromFile(ptr);
1217 
1218  if (!res) { // standard
1219  HRESULT hres = CoCreateInstance(QUuid(ctrl), 0, CLSCTX_SERVER, IID_IUnknown, (void**)ptr);
1220  res = S_OK == hres;
1221 #ifndef QT_NO_DEBUG
1222  if (!res)
1223  qErrnoWarning(hres, "CoCreateInstance failure");
1224 #endif
1225  }
1226 
1227  return *ptr != 0;
1228 }
bool initializeActive(IUnknown **ptr)
Connects to an active instance running on the current machine, and returns the IUnknown interface to ...
Definition: qaxbase.cpp:1321
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
bool initializeRemote(IUnknown **ptr)
Creates the instance on a remote server, and returns the IUnknown interface to the object in ptr...
Definition: qaxbase.cpp:1390
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
static bool isEmpty(const char *str)
QString ctrl
Definition: qaxbase.cpp:590
QAxBasePrivate * d
Definition: qaxbase.h:150
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
const T * ptr(const T &t)
bool initializeFromFile(IUnknown **ptr)
Creates the COM object handling the filename in the control property, and returns the IUnknown interf...
Definition: qaxbase.cpp:1352
long HRESULT
bool initializeLicensed(IUnknown **ptr)
Creates an instance of a licensed control, and returns the IUnknown interface to the object in ptr...
Definition: qaxbase.cpp:1240
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ initializeActive()

bool QAxBase::initializeActive ( IUnknown **  ptr)
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 "}&".

See also
initialize()

Definition at line 1321 of file qaxbase.cpp.

1322 {
1323 #if defined(Q_OS_WINCE)
1324  Q_UNUSED(ptr);
1325  return false;
1326 #else
1327  int at = control().lastIndexOf(QLatin1String("}&"));
1328  QString clsid(control().left(at));
1329 
1330  GetActiveObject(QUuid(clsid), 0, ptr);
1331 
1332  return *ptr != 0;
1333 #endif
1334 }
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
#define at(className, varName)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
const T * ptr(const T &t)
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67

◆ initializeFrom()

void QAxBase::initializeFrom ( QAxBase that)
protected

Used by subclasses generated with dumpcpp to implement cast-operators.

Warning
This function is not part of the public interface.

Definition at line 902 of file qaxbase.cpp.

903 {
904  if (d->ptr)
905  return;
906 
907  d->ptr = that->d->ptr;
908  if (d->ptr) {
909  d->ptr->AddRef();
910  d->initialized = true;
911  }
912 }
IUnknown * ptr
Definition: qaxbase.cpp:600
QAxBasePrivate * d
Definition: qaxbase.h:150
uint initialized
Definition: qaxbase.cpp:597

◆ initializeFromFile()

bool QAxBase::initializeFromFile ( IUnknown **  ptr)
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.

See also
initialize()

Definition at line 1352 of file qaxbase.cpp.

1353 {
1354 #if defined(Q_OS_WINCE)
1355  Q_UNUSED(ptr);
1356  return false;
1357 #else
1358  IStorage *storage = 0;
1359  ILockBytes * bytes = 0;
1360  HRESULT hres = ::CreateILockBytesOnHGlobal(0, TRUE, &bytes);
1361  hres = ::StgCreateDocfileOnILockBytes(bytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &storage);
1362 
1363  hres = OleCreateFromFile(CLSID_NULL, reinterpret_cast<const wchar_t*>(control().utf16()), IID_IUnknown, OLERENDER_NONE, 0, 0, storage, (void**)ptr);
1364 
1365  storage->Release();
1366  bytes->Release();
1367 
1368  return hres == S_OK;
1369 #endif
1370 }
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
const T * ptr(const T &t)
#define TRUE
Synonym for true.
Definition: qglobal.h:1018
long HRESULT
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ initializeLicensed()

bool QAxBase::initializeLicensed ( IUnknown **  ptr)
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.

See also
initialize()

Definition at line 1240 of file qaxbase.cpp.

1241 {
1242  int at = control().lastIndexOf(QLatin1String("}:"));
1243 
1244  QString clsid(control().left(at));
1245  QString key(control().mid(at+2));
1246 
1247  IClassFactory *factory = 0;
1248  CoGetClassObject(QUuid(clsid), CLSCTX_SERVER, 0, IID_IClassFactory, (void**)&factory);
1249  if (!factory)
1250  return false;
1251  initializeLicensedHelper(factory, key, ptr);
1252  factory->Release();
1253 
1254  return *ptr != 0;
1255 }
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
#define at(className, varName)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
const T * ptr(const T &t)
bool initializeLicensedHelper(void *factory, const QString &key, IUnknown **ptr)
Definition: qaxbase.cpp:1261
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
int key
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67

◆ initializeLicensedHelper()

bool QAxBase::initializeLicensedHelper ( void *  factory,
const QString key,
IUnknown **  ptr 
)
private

Definition at line 1261 of file qaxbase.cpp.

1262 {
1263  IClassFactory *factory = (IClassFactory*)f;
1264  IClassFactory2 *factory2 = 0;
1265  factory->QueryInterface(IID_IClassFactory2, (void**)&factory2);
1266  if (factory2) {
1267  BSTR bkey = QStringToBSTR(key);
1268  HRESULT hres = factory2->CreateInstanceLic(0, 0, IID_IUnknown, bkey, (void**)ptr);
1269  SysFreeString(bkey);
1270 #ifdef QT_DEBUG
1271  LICINFO licinfo;
1272  licinfo.cbLicInfo = sizeof(LICINFO);
1273  factory2->GetLicInfo(&licinfo);
1274 
1275  if (hres != S_OK) {
1276  SetLastError(hres);
1277  qErrnoWarning("CreateInstanceLic failed");
1278  if (!licinfo.fLicVerified) {
1279  qWarning("Wrong license key specified, and machine is not fully licensed.");
1280  } else if (licinfo.fRuntimeKeyAvail) {
1281  BSTR licenseKey;
1282  factory2->RequestLicKey(0, &licenseKey);
1283  QString qlicenseKey = QString::fromWCharArray(licenseKey);
1284  SysFreeString(licenseKey);
1285  qWarning("Use license key is '%s' to create object on unlicensed machine.",
1286  qlicenseKey.toLatin1().constData());
1287  }
1288  } else if (licinfo.fLicVerified) {
1289  qWarning("Machine is fully licensed for '%s'", control().toLatin1().constData());
1290  if (licinfo.fRuntimeKeyAvail) {
1291  BSTR licenseKey;
1292  factory2->RequestLicKey(0, &licenseKey);
1293  QString qlicenseKey = QString::fromWCharArray(licenseKey);
1294  SysFreeString(licenseKey);
1295 
1296  if (qlicenseKey != key)
1297  qWarning("Runtime license key is '%s'", qlicenseKey.toLatin1().constData());
1298  }
1299  }
1300 #else
1301  Q_UNUSED(hres);
1302 #endif
1303  factory2->Release();
1304  } else { // give it a shot without license
1305  factory->CreateInstance(0, IID_IUnknown, (void**)ptr);
1306  }
1307  return *ptr != 0;
1308 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qWarning(const char *,...)
const T * ptr(const T &t)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
long HRESULT
static BSTR QStringToBSTR(const QString &str)
Definition: qaxtypes.h:76
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ initializeRemote()

bool QAxBase::initializeRemote ( IUnknown **  ptr)
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.

See also
initialize()

Definition at line 1390 of file qaxbase.cpp.

1391 {
1392  int at = control().lastIndexOf(QLatin1String("/{"));
1393 
1394  QString server(control().left(at));
1395  QString clsid(control().mid(at+1));
1396 
1397  QString user;
1398  QString domain;
1399  QString passwd;
1400  QString key;
1401 
1402  at = server.indexOf(QChar::fromLatin1('@'));
1403  if (at != -1) {
1404  user = server.left(at);
1405  server = server.mid(at+1);
1406 
1407  at = user.indexOf(QChar::fromLatin1(':'));
1408  if (at != -1) {
1409  passwd = user.mid(at+1);
1410  user = user.left(at);
1411  }
1412  at = user.indexOf(QChar::fromLatin1('/'));
1413  if (at != -1) {
1414  domain = user.left(at);
1415  user = user.mid(at+1);
1416  }
1417  }
1418 
1419  at = clsid.lastIndexOf(QLatin1String("}:"));
1420  if (at != -1) {
1421  key = clsid.mid(at+2);
1422  clsid = clsid.left(at);
1423  }
1424 
1425  d->ctrl = server + QChar::fromLatin1('/') + clsid;
1426  if (!key.isEmpty())
1427  d->ctrl = d->ctrl + QChar::fromLatin1(':') + key;
1428 
1429  COAUTHIDENTITY authIdentity;
1430  authIdentity.UserLength = user.length();
1431  authIdentity.User = authIdentity.UserLength ? (ushort*)user.utf16() : 0;
1432  authIdentity.DomainLength = domain.length();
1433  authIdentity.Domain = authIdentity.DomainLength ? (ushort*)domain.utf16() : 0;
1434  authIdentity.PasswordLength = passwd.length();
1435  authIdentity.Password = authIdentity.PasswordLength ? (ushort*)passwd.utf16() : 0;
1436  authIdentity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
1437 
1438  COAUTHINFO authInfo;
1439  authInfo.dwAuthnSvc = RPC_C_AUTHN_WINNT;
1440  authInfo.dwAuthzSvc = RPC_C_AUTHZ_NONE;
1441  authInfo.pwszServerPrincName = 0;
1442  authInfo.dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT;
1443  authInfo.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
1444  authInfo.pAuthIdentityData = &authIdentity;
1445  authInfo.dwCapabilities = 0;
1446 
1447  COSERVERINFO serverInfo;
1448  serverInfo.dwReserved1 = 0;
1449  serverInfo.dwReserved2 = 0;
1450  serverInfo.pAuthInfo = &authInfo;
1451  serverInfo.pwszName = (wchar_t*)server.utf16();
1452 
1453  IClassFactory *factory = 0;
1454  HRESULT res = CoGetClassObject(QUuid(clsid), CLSCTX_REMOTE_SERVER, &serverInfo, IID_IClassFactory, (void**)&factory);
1455  if (factory) {
1456  if (!key.isEmpty())
1457  initializeLicensedHelper(factory, key, ptr);
1458  else
1459  res = factory->CreateInstance(0, IID_IUnknown, (void**)ptr);
1460  factory->Release();
1461  }
1462 #ifndef QT_NO_DEBUG
1463  if (res != S_OK)
1464  qErrnoWarning(res, "initializeRemote Failed");
1465 #endif
1466 
1467  return res == S_OK;
1468 }
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
#define at(className, varName)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString ctrl
Definition: qaxbase.cpp:590
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QAxBasePrivate * d
Definition: qaxbase.h:150
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
const T * ptr(const T &t)
bool initializeLicensedHelper(void *factory, const QString &key, IUnknown **ptr)
Definition: qaxbase.cpp:1261
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
static QAuServer & server()
Definition: qsound.cpp:79
long HRESULT
unsigned short ushort
Definition: qglobal.h:995
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
int key
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ internalInvoke()

int QAxBase::internalInvoke ( QMetaObject::Call  call,
int  index,
void **  v 
)
private

Definition at line 3593 of file qaxbase.cpp.

3594 {
3596  Q_UNUSED(call);
3597 
3598  // get the IDispatch
3599  IDispatch *disp = d->dispatch();
3600  if (!disp)
3601  return index;
3602 
3603  const QMetaObject *mo = metaObject();
3604  // get the slot information
3605  const QMetaMethod slot = mo->method(index + mo->methodOffset());
3607 
3608  QByteArray signature(slot.signature());
3609  QByteArray slotname(signature);
3610  slotname.truncate(slotname.indexOf('('));
3611 
3612  // Get the Dispatch ID of the method to be called
3613  bool isProperty = false;
3614  DISPID dispid = d->metaObject()->dispIDofName(slotname, disp);
3615 
3616  Q_ASSERT(d->metaobj);
3617 
3618  if (dispid == DISPID_UNKNOWN && slotname.toLower().startsWith("set")) {
3619  // see if we are calling a property set function as a slot
3620  slotname = slotname.right(slotname.length() - 3);
3621  dispid = d->metaobj->dispIDofName(slotname, disp);
3622  isProperty = true;
3623  }
3624  if (dispid == DISPID_UNKNOWN)
3625  return index;
3626 
3627  // slot found, so everthing that goes wrong now should not bother the caller
3628  index -= mo->methodCount();
3629 
3630  // setup the parameters
3631  DISPPARAMS params;
3632  DISPID dispidNamed = DISPID_PROPERTYPUT;
3633  params.cArgs = d->metaobj->numParameter(signature);
3634  params.cNamedArgs = isProperty ? 1 : 0;
3635  params.rgdispidNamedArgs = isProperty ? &dispidNamed : 0;
3636  params.rgvarg = 0;
3637  VARIANTARG static_rgvarg[QAX_NUM_PARAMS];
3638  if (params.cArgs) {
3639  if (params.cArgs <= QAX_NUM_PARAMS)
3640  params.rgvarg = static_rgvarg;
3641  else
3642  params.rgvarg = new VARIANTARG[params.cArgs];
3643  }
3644 
3645  int p;
3646  for (p = 0; p < (int)params.cArgs; ++p) {
3647  bool out;
3648  QByteArray type = d->metaobj->paramType(signature, p, &out);
3650  QVariant qvar;
3651  if (vt != QVariant::UserType)
3652  qvar = QVariant(vt, v[p + 1]);
3653 
3654  if (!qvar.isValid()) {
3655  if (type == "IDispatch*")
3656  qvar.setValue(*(IDispatch**)v[p+1]);
3657  else if (type == "IUnknown*")
3658  qvar.setValue(*(IUnknown**)v[p+1]);
3659  else if (type == "QVariant")
3660  qvar = *(QVariant*)v[p + 1];
3661  else if (mo->indexOfEnumerator(type) != -1)
3662  qvar = *(int*)v[p + 1];
3663  else
3664  qvar = QVariant(QMetaType::type(type), v[p + 1]);
3665  }
3666 
3667  QVariantToVARIANT(qvar, params.rgvarg[params.cArgs - p - 1], type, out);
3668  }
3669 
3670  // call the method
3671  VARIANT ret;
3672  VariantInit(&ret);
3673  UINT argerr = 0;
3674  HRESULT hres = E_FAIL;
3675  EXCEPINFO excepinfo;
3676  memset(&excepinfo, 0, sizeof(excepinfo));
3677 
3678  WORD wFlags = isProperty ? DISPATCH_PROPERTYPUT : DISPATCH_METHOD | DISPATCH_PROPERTYGET;
3679  hres = disp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, wFlags, &params, &ret, &excepinfo, &argerr);
3680 
3681  // get return value
3682  if (hres == S_OK && ret.vt != VT_EMPTY)
3683  QVariantToVoidStar(VARIANTToQVariant(ret, slot.typeName()), v[0], slot.typeName());
3684 
3685  // update out parameters
3686  for (p = 0; p < (int)params.cArgs; ++p) {
3687  bool out;
3688  QByteArray ptype = d->metaobj->paramType(signature, p, &out);
3689  if (out)
3690  QVariantToVoidStar(VARIANTToQVariant(params.rgvarg[params.cArgs - p - 1], ptype), v[p+1], ptype);
3691  }
3692  // clean up
3693  for (p = 0; p < (int)params.cArgs; ++p)
3694  clearVARIANT(params.rgvarg+p);
3695  if (params.rgvarg != static_rgvarg)
3696  delete [] params.rgvarg;
3697 
3698  checkHRESULT(hres, &excepinfo, this, QString::fromLatin1(slotname), params.cArgs-argerr-1);
3699  return index;
3700 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void clearVARIANT(VARIANT *var)
Definition: qaxtypes.cpp:1408
int type
Definition: qmetatype.cpp:239
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
#define QAX_NUM_PARAMS
Definition: qaxtypes.h:74
QAxMetaObject * metaobj
Definition: qaxbase.cpp:614
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool checkHRESULT(HRESULT hres, EXCEPINFO *exc, QAxBase *that, const QString &name, uint argerr)
Definition: qaxbase.cpp:3396
int numParameter(const QByteArray &prototype)
Definition: qaxbase.cpp:134
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
void setValue(const T &value)
Stores a copy of value.
Definition: qvariant.h:527
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int methodOffset() const
Returns the method offset for this class; i.e.
QAxBasePrivate * d
Definition: qaxbase.h:150
bool QVariantToVARIANT(const QVariant &var, VARIANT &arg, const QByteArray &typeName, bool out)
Definition: qaxtypes.cpp:246
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
QByteArray paramType(const QByteArray &signature, int index, bool *out=0)
Definition: qaxbase.cpp:142
bool QVariantToVoidStar(const QVariant &var, void *data, const QByteArray &typeName, uint type)
Copies the data in var into data.
Definition: qaxtypes.cpp:814
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
long HRESULT
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
Returns arg as a QVariant of type type.
Definition: qaxtypes.cpp:919
quint16 index
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
DISPID dispIDofName(const QByteArray &name, IDispatch *disp)
Definition: qaxbase.cpp:168
QAxMetaObject * metaObject()
Definition: qaxbase.cpp:605
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
int indexOfEnumerator(const char *name) const
Finds enumerator name and returns its index; otherwise returns -1.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static Type nameToType(const char *name)
Converts the string representation of the storage type given in name, to its enum representation...
Definition: qvariant.cpp:2026
IDispatch * dispatch() const
Definition: qaxbase.cpp:580
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56

◆ internalMetaObject()

QAxMetaObject * QAxBase::internalMetaObject ( ) const
private

Definition at line 915 of file qaxbase.cpp.

916 {
917  return d->metaObject();
918 }
QAxBasePrivate * d
Definition: qaxbase.h:150
QAxMetaObject * metaObject()
Definition: qaxbase.cpp:605

◆ internalProperty()

int QAxBase::internalProperty ( QMetaObject::Call  call,
int  index,
void **  v 
)
private
Warning
This function is not part of the public interface.

Definition at line 3476 of file qaxbase.cpp.

3477 {
3478  const QMetaObject *mo = metaObject();
3479  const QMetaProperty prop = mo->property(index + mo->propertyOffset());
3480  QByteArray propname = prop.name();
3481 
3482  // hardcoded control property
3483  if (propname == "control") {
3484  switch(call) {
3486  *(QString*)*v = control();
3487  break;
3489  setControl(*(QString*)*v);
3490  break;
3492  clear();
3493  break;
3494  default:
3495  break;
3496  }
3497  return index - mo->propertyCount();
3498  }
3499 
3500  // get the IDispatch
3501  if (!d->ptr || !prop.isValid())
3502  return index;
3503  IDispatch *disp = d->dispatch();
3504  if (!disp)
3505  return index;
3506 
3507  DISPID dispid = d->metaObject()->dispIDofName(propname, disp);
3508  if (dispid == DISPID_UNKNOWN)
3509  return index;
3510 
3511  Q_ASSERT(d->metaobj);
3512  // property found, so everthing that goes wrong now should not bother the caller
3513  index -= mo->propertyCount();
3514 
3515  VARIANTARG arg;
3516  VariantInit(&arg);
3517  DISPPARAMS params;
3518  EXCEPINFO excepinfo;
3519  memset(&excepinfo, 0, sizeof(excepinfo));
3520  UINT argerr = 0;
3521  HRESULT hres = E_FAIL;
3522 
3523  QByteArray proptype(prop.typeName());
3524  switch (call) {
3526  {
3527  params.cArgs = 0;
3528  params.cNamedArgs = 0;
3529  params.rgdispidNamedArgs = 0;
3530  params.rgvarg = 0;
3531 
3532  hres = disp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &params, &arg, &excepinfo, 0);
3533 
3534  // map result VARIANTARG to void*
3536  if (!prop.isEnumType())
3537  type = prop.type();
3538  QVariantToVoidStar(VARIANTToQVariant(arg, proptype, type), *v, proptype, type);
3539  if ((arg.vt != VT_DISPATCH && arg.vt != VT_UNKNOWN) || type == QVariant::Pixmap || type == QVariant::Font)
3540  clearVARIANT(&arg);
3541  }
3542  break;
3543 
3545  {
3546  QVariant::Type t = (QVariant::Type)prop.type();
3547 
3548  DISPID dispidNamed = DISPID_PROPERTYPUT;
3549  params.cArgs = 1;
3550  params.cNamedArgs = 1;
3551  params.rgdispidNamedArgs = &dispidNamed;
3552  params.rgvarg = &arg;
3553 
3554  arg.vt = VT_ERROR;
3555  arg.scode = DISP_E_TYPEMISMATCH;
3556 
3557  // map void* to VARIANTARG via QVariant
3558  QVariant qvar;
3559  if (prop.isEnumType()) {
3560  qvar = *(int*)v[0];
3561  proptype = 0;
3562  } else {
3563  if (t == QVariant::LastType) {
3564  qvar = *(QVariant*)v[0];
3565  proptype = 0;
3566  } else if (t == QVariant::UserType) {
3567  qvar = QVariant(qRegisterMetaType<void*>(prop.typeName()), (void**)v[0]);
3568 // qvar.setValue(*(void**)v[0], prop.typeName());
3569  } else {
3570  proptype = d->metaObject()->propertyType(propname);
3571  qvar = QVariant(t, v[0]);
3572  }
3573  }
3574 
3575  QVariantToVARIANT(qvar, arg, proptype);
3576  if (arg.vt == VT_EMPTY || arg.vt == VT_ERROR) {
3577  qWarning("QAxBase::setProperty: Unhandled property type %s", prop.typeName());
3578  break;
3579  }
3580  }
3581  hres = disp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &params, 0, &excepinfo, &argerr);
3582  clearVARIANT(&arg);
3583  break;
3584 
3585  default:
3586  break;
3587  }
3588 
3589  checkHRESULT(hres, &excepinfo, this, QLatin1String(propname), argerr);
3590  return index;
3591 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
IUnknown * ptr
Definition: qaxbase.cpp:600
void clearVARIANT(VARIANT *var)
Definition: qaxtypes.cpp:1408
int type
Definition: qmetatype.cpp:239
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
QAxMetaObject * metaobj
Definition: qaxbase.cpp:614
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool checkHRESULT(HRESULT hres, EXCEPINFO *exc, QAxBase *that, const QString &name, uint argerr)
Definition: qaxbase.cpp:3396
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool isValid() const
Returns true if this property is valid (readable); otherwise returns false.
Definition: qmetaobject.h:213
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
QByteArray propertyType(const QByteArray &propertyName)
Definition: qaxbase.cpp:129
QAxBasePrivate * d
Definition: qaxbase.h:150
bool QVariantToVARIANT(const QVariant &var, VARIANT &arg, const QByteArray &typeName, bool out)
Definition: qaxtypes.cpp:246
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
bool setControl(const QString &)
Definition: qaxbase.cpp:975
bool QVariantToVoidStar(const QVariant &var, void *data, const QByteArray &typeName, uint type)
Copies the data in var into data.
Definition: qaxtypes.cpp:814
long HRESULT
const char * name() const
Returns this property&#39;s name.
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
Returns arg as a QVariant of type type.
Definition: qaxtypes.cpp:919
quint16 index
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
DISPID dispIDofName(const QByteArray &name, IDispatch *disp)
Definition: qaxbase.cpp:168
QAxMetaObject * metaObject()
Definition: qaxbase.cpp:605
int propertyOffset() const
Returns the property offset for this class; i.e.
IDispatch * dispatch() const
Definition: qaxbase.cpp:580
virtual void clear()
Disconnects and destroys the COM object.
Definition: qaxbase.cpp:1095
const char * typeName() const
Returns the name of this property&#39;s type.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
QVariant::Type type() const
Returns this property&#39;s type.

◆ internalRelease()

void QAxBase::internalRelease ( )
protected

Used by subclasses generated with dumpcpp to balance reference count.

Warning
This function is not part of the public interface.

Definition at line 888 of file qaxbase.cpp.

889 {
890  if (d->ptr)
891  d->ptr->Release();
892 }
IUnknown * ptr
Definition: qaxbase.cpp:600
QAxBasePrivate * d
Definition: qaxbase.h:150

◆ isNull()

bool QAxBase::isNull ( ) const

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

See also
control

Definition at line 4412 of file qaxbase.cpp.

Referenced by QAxWidget::changeEvent(), QAxWidget::clear(), and qax_generateDocumentation().

4413 {
4414  return !d->ptr;
4415 }
IUnknown * ptr
Definition: qaxbase.cpp:600
QAxBasePrivate * d
Definition: qaxbase.h:150

◆ metaObject()

const QMetaObject * QAxBase::metaObject ( ) const
virtual

The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo interface implementations in the COM object.

Warning
This function is not part of the public interface.

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().

3246 {
3247  if (d->metaobj)
3248  return d->metaobj;
3249  const QMetaObject* parentObject = parentMetaObject();
3250 
3251  if (!d->ptr && !d->initialized) {
3252  ((QAxBase*)this)->initialize(&d->ptr);
3253  d->initialized = true;
3254  }
3255 
3256 #ifndef QT_NO_THREAD
3257  // only one thread at a time can generate meta objects
3258  QMutexLocker locker(&cache_mutex);
3259 #endif
3260 
3261  // return the default meta object if not yet initialized
3262  if (!d->ptr || !d->useMetaObject) {
3263  if (qObject()->isWidgetType())
3266  }
3267  MetaObjectGenerator generator((QAxBase*)this, d);
3268  return generator.metaObject(parentObject);
3269 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
IUnknown * ptr
Definition: qaxbase.cpp:600
virtual QObject * qObject() const =0
QAxMetaObject * metaobj
Definition: qaxbase.cpp:614
virtual const QMetaObject * parentMetaObject() const =0
QAxBasePrivate * d
Definition: qaxbase.h:150
static QMutex cache_mutex
Definition: qaxbase.cpp:186
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QMetaObject qaxobject_staticMetaObject
Definition: qaxbase.cpp:3226
uint initialized
Definition: qaxbase.cpp:597
static QMetaObject qaxwidget_staticMetaObject
Definition: qaxbase.cpp:3230
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
Definition: qaxbase.h:66
uint useMetaObject
Definition: qaxbase.cpp:594

◆ parentMetaObject()

virtual const QMetaObject* QAxBase::parentMetaObject ( ) const
privatepure virtual

Implemented in QAxWidget, and QAxObject.

◆ propertyBag()

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.

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.

Definition at line 4303 of file qaxbase.cpp.

Referenced by operator<<().

4304 {
4305  PropertyBag result;
4306 
4307  if (!d->ptr && !d->initialized) {
4308  ((QAxBase*)this)->initialize(&d->ptr);
4309  d->initialized = true;
4310  }
4311 
4312  if (isNull())
4313  return result;
4314  IPersistPropertyBag *persist = 0;
4315  d->ptr->QueryInterface(IID_IPersistPropertyBag, (void**)&persist);
4316  if (persist) {
4317  QtPropertyBag *pbag = new QtPropertyBag();
4318  pbag->AddRef();
4319  persist->Save(pbag, false, true);
4320  result = pbag->map;
4321  pbag->Release();
4322  persist->Release();
4323  return result;
4324  } else {
4325  const QMetaObject *mo = metaObject();
4326  for (int p = mo->propertyOffset(); p < mo->propertyCount(); ++p) {
4327  const QMetaProperty property = mo->property(p);
4328  QVariant var = qObject()->property(property.name());
4329  result.insert(QLatin1String(property.name()), var);
4330  }
4331  }
4332  return result;
4333 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
IUnknown * ptr
Definition: qaxbase.cpp:600
bool isNull() const
Returns true if there is no COM object loaded by this wrapper; otherwise return false.
Definition: qaxbase.cpp:4412
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
virtual QObject * qObject() const =0
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
QMap< QString, QVariant > PropertyBag
A QMap<QString,QVariant> that can store properties as name:value pairs.
Definition: qaxbase.h:71
unsigned long __stdcall Release()
Definition: qaxbase.cpp:4255
unsigned long __stdcall AddRef()
Definition: qaxbase.cpp:4251
QAxBasePrivate * d
Definition: qaxbase.h:150
QAxBase::PropertyBag map
Definition: qaxbase.cpp:4285
uint initialized
Definition: qaxbase.cpp:597
const char * property
Definition: qwizard.cpp:138
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
int propertyOffset() const
Returns the property offset for this class; i.e.
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
Definition: qaxbase.h:66
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ propertyChanged

void QAxBase::propertyChanged ( const QString name)
signal

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

◆ propertyWritable()

bool QAxBase::propertyWritable ( const char *  prop) const
virtual

Returns true if the property prop 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 also
setPropertyWritable(), propertyChanged()

Definition at line 4385 of file qaxbase.cpp.

4386 {
4387  return d->propWritable.value(prop, true);
4388 }
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
QAxBasePrivate * d
Definition: qaxbase.h:150
QMap< QByteArray, bool > propWritable
Definition: qaxbase.cpp:603

◆ qObject()

QObject * QAxBase::qObject ( ) const
pure virtual
Warning
This function is not part of the public interface.

Implemented in QAxWidget, and QAxObject.

Referenced by checkHRESULT(), operator>>(), and qax_generateDocumentation().

◆ qt_metacall()

int QAxBase::qt_metacall ( QMetaObject::Call  call,
int  id,
void **  v 
)
virtual
Warning
This function is not part of the public interface.

Reimplemented in QAxWidget, and QAxObject.

Definition at line 3705 of file qaxbase.cpp.

Referenced by checkHRESULT(), QAxObject::qt_metacall(), and QAxWidget::qt_metacall().

3706 {
3707  const QMetaObject *mo = metaObject();
3708  if (isNull() && mo->property(id + mo->propertyOffset()).name() != QByteArray("control")) {
3709  qWarning("QAxBase::qt_metacall: Object is not initialized, or initialization failed");
3710  return id;
3711  }
3712 
3713  switch(call) {
3715  switch (mo->method(id + mo->methodOffset()).methodType()) {
3716  case QMetaMethod::Signal:
3717  QMetaObject::activate(qObject(), mo, id, v);
3718  id -= mo->methodCount();
3719  break;
3720  case QMetaMethod::Method:
3721  case QMetaMethod::Slot:
3722  id = internalInvoke(call, id, v);
3723  break;
3724  default:
3725  break;
3726  }
3727  break;
3731  id = internalProperty(call, id, v);
3732  break;
3738  id -= mo->propertyCount();
3739  break;
3740  default:
3741  break;
3742  }
3743  Q_ASSERT(id < 0);
3744  return id;
3745 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
bool isNull() const
Returns true if there is no COM object loaded by this wrapper; otherwise return false.
Definition: qaxbase.cpp:4412
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
virtual QObject * qObject() const =0
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int methodOffset() const
Returns the method offset for this class; i.e.
int internalProperty(QMetaObject::Call, int index, void **v)
Definition: qaxbase.cpp:3476
int internalInvoke(QMetaObject::Call, int index, void **v)
Definition: qaxbase.cpp:3593
const char * name
Q_CORE_EXPORT void qWarning(const char *,...)
static void activate(QObject *sender, int signal_index, void **argv)
Definition: qobject.cpp:3690
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
int propertyOffset() const
Returns the property offset for this class; i.e.
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ queryInterface()

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.

See also
control

Definition at line 1479 of file qaxbase.cpp.

Referenced by QAxClientSite::activateObject(), QAxObject::doVerb(), QAxScriptSite::GetItemInfo(), QAxScriptEngine::hasIntrospection(), QAxHostWidget::paintEvent(), qax_generateDocumentation(), and QVariantToVARIANT().

1480 {
1481  *iface = 0;
1482  if (!d->ptr) {
1483  ((QAxBase*)this)->initialize(&d->ptr);
1484  d->initialized = true;
1485  }
1486 
1487  if (d->ptr && !uuid.isNull())
1488  return d->ptr->QueryInterface(uuid, iface);
1489 
1490  return E_NOTIMPL;
1491 }
IUnknown * ptr
Definition: qaxbase.cpp:600
bool isNull() const
Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false...
Definition: quuid.cpp:700
QAxBasePrivate * d
Definition: qaxbase.h:150
uint initialized
Definition: qaxbase.cpp:597
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
Definition: qaxbase.h:66

◆ querySubObject() [1/2]

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.

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

Definition at line 4130 of file qaxbase.cpp.

4139 {
4140  QList<QVariant> vars;
4141  QVariant var = var1;
4142  int argc = 1;
4143  while(var.isValid()) {
4144  vars << var;
4145  switch(++argc) {
4146  case 2: var = var2; break;
4147  case 3: var = var3; break;
4148  case 4: var = var4; break;
4149  case 5: var = var5; break;
4150  case 6: var = var6; break;
4151  case 7: var = var7; break;
4152  case 8: var = var8; break;
4153  default:var = QVariant(); break;
4154  }
4155  }
4156 
4157  return querySubObject(name, vars);
4158 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
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...
Definition: qaxbase.cpp:4130
const char * name
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ querySubObject() [2/2]

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

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.

4170 {
4171  QAxObject *object = 0;
4172  VARIANTARG res;
4173  VariantInit(&res);
4174 
4175  QByteArray rettype;
4176  if (!dynamicCallHelper(name, &res, vars, rettype))
4177  return 0;
4178 
4179  switch (res.vt) {
4180  case VT_DISPATCH:
4181  if (res.pdispVal) {
4182  if (rettype.isEmpty() || rettype == "IDispatch*" || rettype == "QVariant") {
4183  object = new QAxObject(res.pdispVal, qObject());
4184  } else if (QMetaType::type(rettype)) {
4185  QVariant qvar = VARIANTToQVariant(res, rettype, 0);
4186  object = *(QAxObject**)qvar.constData();
4187 // qVariantGet(qvar, object, rettype);
4188  res.pdispVal->AddRef();
4189  }
4190  if (object)
4191  ((QAxBase*)object)->d->tryCache = true;
4192  }
4193  break;
4194  case VT_UNKNOWN:
4195  if (res.punkVal) {
4196  if (rettype.isEmpty() || rettype == "IUnknown*") {
4197  object = new QAxObject(res.punkVal, qObject());
4198  } else if (QMetaType::type(rettype)) {
4199  QVariant qvar = VARIANTToQVariant(res, rettype, 0);
4200  object = *(QAxObject**)qvar.constData();
4201 // qVariantGet(qvar, object, rettype);
4202  res.punkVal->AddRef();
4203  }
4204  if (object)
4205  ((QAxBase*)object)->d->tryCache = true;
4206  }
4207  break;
4208  case VT_EMPTY:
4209 #ifdef QT_CHECK_STATE
4210  {
4211  const char *coclass = metaObject()->classInfo(metaObject()->indexOfClassInfo("CoClass")).value();
4212  qWarning("QAxBase::querySubObject: %s: Error calling function or property in %s (%s)"
4213  , name, control().toLatin1().data(), coclass ? coclass: "unknown");
4214  }
4215 #endif
4216  break;
4217  default:
4218 #ifdef QT_CHECK_STATE
4219  {
4220  const char *coclass = metaObject()->classInfo(metaObject()->indexOfClassInfo("CoClass")).value();
4221  qWarning("QAxBase::querySubObject: %s: Method or property is not of interface type in %s (%s)"
4222  , name, control().toLatin1().data(), coclass ? coclass: "unknown");
4223  }
4224 #endif
4225  break;
4226  }
4227 
4228  clearVARIANT(&res);
4229  return object;
4230 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void clearVARIANT(VARIANT *var)
Definition: qaxtypes.cpp:1408
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
bool dynamicCallHelper(const char *name, void *out, QList< QVariant > &var, QByteArray &type)
Definition: qaxbase.cpp:3784
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
virtual QObject * qObject() const =0
QMetaClassInfo classInfo(int index) const
Returns the meta-data for the item of class information with the given index.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QAxObject class provides a QObject that wraps a COM object.
Definition: qaxobject.h:54
const char * value() const
Returns the value of this item.
const char * name
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
const void * constData() const
Definition: qvariant.cpp:3065
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
Returns arg as a QVariant of type type.
Definition: qaxtypes.cpp:919
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
Definition: qaxbase.h:66

◆ setControl()

bool QAxBase::setControl ( const QString c)

Definition at line 975 of file qaxbase.cpp.

Referenced by operator>>(), QAxObject::QAxObject(), and QAxWidget::QAxWidget().

976 {
977  if (c.toLower() == d->ctrl.toLower())
978  return !d->ctrl.isEmpty();
979 
980  QString search = c;
981  // don't waste time for DCOM requests
982  int dcomIDIndex = search.indexOf(QLatin1String("/{"));
983  if ((dcomIDIndex == -1 || dcomIDIndex != search.length()-39) && !search.endsWith(QLatin1String("}&"))) {
984  QUuid uuid(search);
985  if (uuid.isNull()) {
986  CLSID clsid;
987  HRESULT res = CLSIDFromProgID((wchar_t*)c.utf16(), &clsid);
988  if (res == S_OK)
989  search = QUuid(clsid).toString();
990  else {
991  QSettings controls(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Classes\\"), QSettings::NativeFormat);
992  search = controls.value(c + QLatin1String("/CLSID/Default")).toString();
993  if (search.isEmpty()) {
994  controls.beginGroup(QLatin1String("/CLSID"));
995  QStringList clsids = controls.childGroups();
996  for (QStringList::Iterator it = clsids.begin(); it != clsids.end(); ++it) {
997  QString clsid = *it;
998  QString name = controls.value(clsid + QLatin1String("/Default")).toString();
999  if (name == c) {
1000  search = clsid;
1001  break;
1002  }
1003  }
1004  controls.endGroup();
1005  }
1006  }
1007  }
1008  if (search.isEmpty())
1009  search = c;
1010  }
1011 
1012  if (search.toLower() == d->ctrl.toLower())
1013  return !d->ctrl.isEmpty();
1014 
1015  clear();
1016  d->ctrl = search;
1017 
1018  d->tryCache = true;
1019  if (!initialize(&d->ptr))
1020  d->initialized = true;
1021  if (isNull()) {
1022  qWarning("QAxBase::setControl: requested control %s could not be instantiated", c.toLatin1().data());
1023  clear();
1024  return false;
1025  }
1026  return true;
1027 }
IUnknown * ptr
Definition: qaxbase.cpp:600
bool isNull() const
Returns true if there is no COM object loaded by this wrapper; otherwise return false.
Definition: qaxbase.cpp:4412
unsigned char c[8]
Definition: qnumeric_p.h:62
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
#define it(className, varName)
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString toString() const
Returns the string representation of this QUuid.
Definition: quuid.cpp:512
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278
QString ctrl
Definition: qaxbase.cpp:590
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QAxBasePrivate * d
Definition: qaxbase.h:150
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
long HRESULT
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
uint initialized
Definition: qaxbase.cpp:597
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
virtual void clear()
Disconnects and destroys the COM object.
Definition: qaxbase.cpp:1095
virtual bool initialize(IUnknown **ptr)
This virtual function is called by setControl() and creates the requested COM object.
Definition: qaxbase.cpp:1199
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ setPropertyBag()

void QAxBase::setPropertyBag ( const PropertyBag bag)

Sets the properties of the COM object to the corresponding values in bag.

Warning
You should only set property bags that have been returned by the propertyBag 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 also
propertyBag()

Definition at line 4347 of file qaxbase.cpp.

Referenced by operator>>().

4348 {
4349  if (!d->ptr && !d->initialized) {
4350  initialize(&d->ptr);
4351  d->initialized = true;
4352  }
4353 
4354  if (isNull())
4355  return;
4356  IPersistPropertyBag *persist = 0;
4357  d->ptr->QueryInterface(IID_IPersistPropertyBag, (void**)&persist);
4358  if (persist) {
4359  QtPropertyBag *pbag = new QtPropertyBag();
4360  pbag->map = bag;
4361  pbag->AddRef();
4362  persist->Load(pbag, 0);
4363  pbag->Release();
4364  persist->Release();
4365  } else {
4366  const QMetaObject *mo = metaObject();
4367  for (int p = mo->propertyOffset(); p < mo->propertyCount(); ++p) {
4368  const QMetaProperty property = mo->property(p);
4369  QVariant var = bag.value(QLatin1String(property.name()));
4370  qObject()->setProperty(property.name(), var);
4371  }
4372  }
4373 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
IUnknown * ptr
Definition: qaxbase.cpp:600
bool isNull() const
Returns true if there is no COM object loaded by this wrapper; otherwise return false.
Definition: qaxbase.cpp:4412
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
virtual QObject * qObject() const =0
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
unsigned long __stdcall Release()
Definition: qaxbase.cpp:4255
unsigned long __stdcall AddRef()
Definition: qaxbase.cpp:4251
QAxBasePrivate * d
Definition: qaxbase.h:150
QAxBase::PropertyBag map
Definition: qaxbase.cpp:4285
uint initialized
Definition: qaxbase.cpp:597
const char * property
Definition: qwizard.cpp:138
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
int propertyOffset() const
Returns the property offset for this class; i.e.
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332
virtual bool initialize(IUnknown **ptr)
This virtual function is called by setControl() and creates the requested COM object.
Definition: qaxbase.cpp:1199
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ setPropertyWritable()

void QAxBase::setPropertyWritable ( const char *  prop,
bool  ok 
)
virtual

Sets the property prop to writable if ok is true, otherwise sets prop 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 also
propertyWritable(), propertyChanged()

Definition at line 4401 of file qaxbase.cpp.

4402 {
4403  d->propWritable[prop] = ok;
4404 }
QAxBasePrivate * d
Definition: qaxbase.h:150
QMap< QByteArray, bool > propWritable
Definition: qaxbase.cpp:603

◆ signal

void QAxBase::signal ( const QString name,
int  argc,
void *  argv 
)
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.

void Receiver::slot(const QString &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 signal name.

Referenced by QAxObject::qObject(), and QAxWidget::qObject().

◆ verbs()

QStringList QAxBase::verbs ( ) const

Returns the list of verbs that the COM object can execute.

Since
4.1

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().

1138 {
1139  if (!d->ptr)
1140  return QStringList();
1141 
1142  if (d->verbs.isEmpty()) {
1143  IOleObject *ole = 0;
1144  d->ptr->QueryInterface(IID_IOleObject, (void**)&ole);
1145  if (ole) {
1146  IEnumOLEVERB *enumVerbs = 0;
1147  ole->EnumVerbs(&enumVerbs);
1148  if (enumVerbs) {
1149  enumVerbs->Reset();
1150  ULONG c;
1151  OLEVERB verb;
1152  while (enumVerbs->Next(1, &verb, &c) == S_OK) {
1153  if (!verb.lpszVerbName)
1154  continue;
1155  QString verbName = QString::fromWCharArray(verb.lpszVerbName);
1156  if (!verbName.isEmpty())
1157  d->verbs.insert(verbName, verb.lVerb);
1158  }
1159  enumVerbs->Release();
1160  }
1161  ole->Release();
1162  }
1163  }
1164 
1165  return d->verbs.keys();
1166 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
IUnknown * ptr
Definition: qaxbase.cpp:600
unsigned char c[8]
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QAxBasePrivate * d
Definition: qaxbase.h:150
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
QMap< QString, LONG > verbs
Definition: qaxbase.cpp:612

Friends and Related Functions

◆ qax_createObjectWrapper

void* qax_createObjectWrapper ( int  ,
IUnknown *   
)
friend

Definition at line 4448 of file qaxbase.cpp.

4449 {
4450  if (!iface)
4451  return 0;
4452 
4453  QAxObject *object = (QAxObject*)QMetaType::construct(metaType, 0);
4454  QAxBasePrivate *d = object->d;
4455 
4456  d->ptr = iface;
4457  d->initialized = true;
4458 
4459  // no release, since no addref
4460 
4461  return object;
4462 }
IUnknown * ptr
Definition: qaxbase.cpp:600
The QAxObject class provides a QObject that wraps a COM object.
Definition: qaxobject.h:54
static void * construct(int type, const void *copy=0)
Returns a copy of copy, assuming it is of type type.
Definition: qmetatype.cpp:1042
QAxBasePrivate * d
Definition: qaxbase.h:150
uint initialized
Definition: qaxbase.cpp:597

◆ QAxEventSink

friend class QAxEventSink
friend

Definition at line 147 of file qaxbase.h.

Properties

◆ d

QAxBasePrivate* QAxBase::d
private

Definition at line 150 of file qaxbase.h.

Referenced by initializeFrom().

◆ staticMetaObject

QMetaObject QAxBase::staticMetaObject
staticprivate

Definition at line 158 of file qaxbase.h.


The documentation for this class was generated from the following files: