Qt 4.8
Classes | Macros | Functions
qaxfactory.h File Reference
#include <QtCore/qhash.h>
#include <QtCore/quuid.h>
#include <QtCore/qfactoryinterface.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qstringlist.h>

Go to the source code of this file.

Classes

class  QAxClass< T >
 
class  QAxFactory
 The QAxFactory class defines a factory for the creation of COM components. More...
 

Macros

#define Q_COM_METATYPE_DECLARED
 
#define QAXCLASS(Class)
 This macro adds a creatable COM class Class to the QAxFactory declared with the QAXFACTORY_BEGIN() macro. More...
 
#define QAXFACTORY_BEGIN(IDTypeLib, IDApp)
 This macro can be used to export multiple QObject classes through an implicitly declared QAxFactory implementation. More...
 
#define QAXFACTORY_DEFAULT(Class, IIDClass, IIDInterface, IIDEvents, IIDTypeLib, IIDApp)
 This macro can be used to export a single QObject subclass Class a this COM server through an implicitly declared QAxFactory implementation. More...
 
#define QAXFACTORY_END()
 Completes the QAxFactory declaration started with the QAXFACTORY_BEGIN() macro. More...
 
#define QAXFACTORY_EXPORT(IMPL, TYPELIB, APPID)
 This macro can be used to export a QAxFactory implementation Class from a COM server. More...
 
#define QAXTYPE(Class)
 This macro adds a non-creatable COM class Class to the QAxFactory declared with the QAXFACTORY_BEGIN(). More...
 

Functions

bool qax_startServer (QAxFactory::ServerType)
 
bool qax_stopServer ()
 
QAxFactoryqAxFactory ()
 

Macro Definition Documentation

◆ Q_COM_METATYPE_DECLARED

#define Q_COM_METATYPE_DECLARED

Definition at line 300 of file qaxfactory.h.

◆ QAXCLASS

#define QAXCLASS (   Class)
Value:
factory = new QAxClass<Class>(typeLibID(), appID()); \
qRegisterMetaType<Class*>(#Class"*"); \
keys = factory->featureList(); \
for (it = keys.begin(); it != keys.end(); ++it) { \
factoryKeys += *it; \
factories.insert(*it, factory); \
creatable.insert(*it, true); \
}\
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QStringList featureList() const
Reimplement this function to return a list of the widgets (class names) supported by this factory...
Definition: qaxfactory.h:196
QStringList keys
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270

This macro adds a creatable COM class Class to the QAxFactory declared with the QAXFACTORY_BEGIN() macro.

See also
QAXFACTORY_BEGIN(), QAXTYPE(), QAXFACTORY_END(), Q_CLASSINFO()

Definition at line 223 of file qaxfactory.h.

◆ QAXFACTORY_BEGIN

#define QAXFACTORY_BEGIN (   IDTypeLib,
  IDApp 
)
Value:
QT_BEGIN_NAMESPACE \
class QAxFactoryList : public QAxFactory \
{ \
QStringList factoryKeys; \
QHash<QString, QAxFactory*> factories; \
QHash<QString, bool> creatable; \
public: \
QAxFactoryList() \
: QAxFactory(IDTypeLib, IDApp) \
{ \
QAxFactory *factory = 0; \
QStringList keys; \
#define it(className, varName)
The QAxFactory class defines a factory for the creation of COM components.
Definition: qaxfactory.h:64
QStringList keys
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278

This macro can be used to export multiple QObject classes through an implicitly declared QAxFactory implementation.

All QObject classes have to declare the ClassID, InterfaceID and EventsID (if applicable) through the Q_CLASSINFO() macro. All declarations will be in a type library with the id IDTypeLib, and if the server is an executable server then it will have the application id IDApp.

This macro needs to be used together with the QAXCLASS(), QAXTYPE() and QAXFACTORY_END() macros.

"{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID
)
QAXCLASS(Class1)
QAXCLASS(Class2)

Definition at line 208 of file qaxfactory.h.

◆ QAXFACTORY_DEFAULT

#define QAXFACTORY_DEFAULT (   Class,
  IIDClass,
  IIDInterface,
  IIDEvents,
  IIDTypeLib,
  IIDApp 
)

This macro can be used to export a single QObject subclass Class a this COM server through an implicitly declared QAxFactory implementation.

This macro exports the class Class as a COM coclass with the CLSID ClassID. The properties and slots will be declared through a COM interface with the IID InterfaceID, and signals will be declared through a COM event interface with the IID EventID. All declarations will be in a type library with the id LibID, and if the server is an executable server then it will have the application id AppID.

#include <qaxfactory.h>
#include "theactivex.h"
TheActiveX, // widget class
"{01234567-89AB-CDEF-0123-456789ABCDEF}", // class ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}", // interface ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}", // event interface ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID
)
See also
QAXFACTORY_EXPORT(), QAXFACTORY_BEGIN()

Definition at line 138 of file qaxfactory.h.

◆ QAXFACTORY_END

#define QAXFACTORY_END ( )

Completes the QAxFactory declaration started with the QAXFACTORY_BEGIN() macro.

See also
QAXFACTORY_BEGIN(), QAXCLASS(), QAXTYPE()

Definition at line 243 of file qaxfactory.h.

◆ QAXFACTORY_EXPORT

#define QAXFACTORY_EXPORT (   IMPL,
  TYPELIB,
  APPID 
)
Value:
QT_BEGIN_NAMESPACE \
QAxFactory *qax_instantiate() \
{ \
IMPL *impl = new IMPL(QUuid(TYPELIB), QUuid(APPID)); \
return impl; \
} \
QT_END_NAMESPACE
QAxFactory * qax_instantiate()
#define IMPL
Definition: qdom.cpp:6666
#define impl(owner, mather, type)
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67

This macro can be used to export a QAxFactory implementation Class from a COM server.

All declarations will be in a type library with the id LibID, and if the server is an executable server then it will have the application id AppID.

MyFactory, // factory class
"{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID
)
See also
QAXFACTORY_BEGIN()

Definition at line 129 of file qaxfactory.h.

◆ QAXTYPE

#define QAXTYPE (   Class)
Value:
factory = new QAxClass<Class>(typeLibID(), appID()); \
qRegisterMetaType<Class*>(#Class"*"); \
keys = factory->featureList(); \
for (it = keys.begin(); it != keys.end(); ++it) { \
factoryKeys += *it; \
factories.insert(*it, factory); \
creatable.insert(*it, false); \
}\
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QStringList featureList() const
Reimplement this function to return a list of the widgets (class names) supported by this factory...
Definition: qaxfactory.h:196
QStringList keys
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270

This macro adds a non-creatable COM class Class to the QAxFactory declared with the QAXFACTORY_BEGIN().

The class Class can be used in APIs of other COM classes exported through QAXTYPE() or QAXCLASS().

Instances of type Class can only be retrieved using APIs of already instantiated objects.

See also
QAXFACTORY_BEGIN(), QAXCLASS(), QAXFACTORY_END(), Q_CLASSINFO()

Definition at line 233 of file qaxfactory.h.

Function Documentation

◆ qax_startServer()

bool qax_startServer ( QAxFactory::ServerType  )

Definition at line 127 of file qaxservermain.cpp.

Referenced by QAxFactory::startServer().

128 {
129  if (qAxIsServer)
130  return true;
131 
132  const QStringList keys = qAxFactory()->featureList();
133  if (!keys.count())
134  return false;
135 
136  if (!qAxFactory()->isService())
137  StartMonitor();
138 
139  classRegistration = new DWORD[keys.count()];
140  int object = 0;
141  for (QStringList::ConstIterator key = keys.begin(); key != keys.end(); ++key, ++object) {
142  IUnknown* p = 0;
143  CLSID clsid = qAxFactory()->classID(*key);
144 
145  // Create a QClassFactory (implemented in qaxserverbase.cpp)
146  HRESULT hRes = GetClassObject(clsid, IID_IClassFactory, (void**)&p);
147  if (SUCCEEDED(hRes))
148  hRes = CoRegisterClassObject(clsid, p, CLSCTX_LOCAL_SERVER,
149  type == QAxFactory::MultipleInstances ? REGCLS_MULTIPLEUSE : REGCLS_SINGLEUSE,
150  classRegistration+object);
151  if (p)
152  p->Release();
153  }
154 
155  qAxIsServer = true;
156  return true;
157 }
int type
Definition: qmetatype.cpp:239
QAxFactory * qAxFactory()
Definition: qaxserver.cpp:81
bool qAxIsServer
Definition: qaxserver.cpp:64
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual QStringList featureList() const =0
Reimplement this function to return a list of the widgets (class names) supported by this factory...
QStringList keys
HRESULT GetClassObject(const GUID &clsid, const GUID &iid, void **ppUnk)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual bool isService() const
Reimplement this function to return true if the server is running as a persistent service (e...
Definition: qaxfactory.cpp:410
long HRESULT
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
int key
static bool StartMonitor()
virtual QUuid classID(const QString &key) const
Reimplement this function to return the class identifier for each key returned by the featureList() i...
Definition: qaxfactory.cpp:191
static DWORD * classRegistration

◆ qax_stopServer()

bool qax_stopServer ( )

Definition at line 162 of file qaxservermain.cpp.

Referenced by QAxFactory::startServer(), and QAxFactory::stopServer().

163 {
165  return true;
166 
167  qAxIsServer = false;
168 
169  const QStringList keys = qAxFactory()->featureList();
170  int object = 0;
171  for (QStringList::ConstIterator key = keys.begin(); key != keys.end(); ++key, ++object)
172  CoRevokeClassObject(classRegistration[object]);
173 
174  delete []classRegistration;
175  classRegistration = 0;
176 
177  Sleep(dwPause); //wait for any threads to finish
178 
179  return true;
180 }
QAxFactory * qAxFactory()
Definition: qaxserver.cpp:81
bool qAxIsServer
Definition: qaxserver.cpp:64
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
virtual QStringList featureList() const =0
Reimplement this function to return a list of the widgets (class names) supported by this factory...
QStringList keys
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
int key
QT_STATIC_CONST DWORD dwPause
static DWORD * classRegistration

◆ qAxFactory()

QAxFactory* qAxFactory ( )

Definition at line 81 of file qaxserver.cpp.

Referenced by qax_create_object_wrapper(), qax_startServer(), qax_stopServer(), QVariantToVARIANT(), and QAxFactory::registerActiveObject().

82 {
83  if (!qax_factory) {
84  bool hadQApp = qApp != 0;
86  // QAxFactory created a QApplication
87  if (!hadQApp && qApp)
88  qax_ownQApp = true;
89 
90  // register all types with metatype system as pointers
92  for (int i = 0; i < keys.count(); ++i) {
93  QString key(keys.at(i));
94  qRegisterMetaType((key + QLatin1Char('*')).toLatin1(), (void**)(quintptr)-1);
95  }
96  }
97  return qax_factory;
98 }
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
QAxFactory * qax_instantiate()
bool qax_ownQApp
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int qRegisterMetaType()
Call this function to register the type T.
Definition: qmetatype.h:234
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QStringList featureList() const =0
Reimplement this function to return a list of the widgets (class names) supported by this factory...
QStringList keys
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int key
static QAxFactory * qax_factory
Definition: qaxserver.cpp:71
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55