QAxFactory Class
The QAxFactory class defines a factory for the creation of COM components. More...
Header: | #include <QAxFactory> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS AxServer) target_link_libraries(mytarget PRIVATE Qt6::AxServer) |
qmake: | QT += axserver |
Macros
QAXCLASS(Class) | |
QAXFACTORY_BEGIN(IDTypeLib, IDApp) | |
QAXFACTORY_END | |
QAXFACTORY_EXPORT(Class, LibID, AppID) | |
QAXTYPE(Class) |
Detailed Description
Implement this factory once in your COM server to provide information about the components the server can create. Subclass QAxFactory and implement the pure virtual functions in any implementation file (e.g. main.cpp), and export the factory using the QAXFACTORY_EXPORT()
macro.
QStringList ActiveQtFactory::featureList() const { QStringList list; list << "ActiveX1"; list << "ActiveX2"; return list; } QObject *ActiveQtFactory::createObject(const QString &key) { if (key == "ActiveX1") return new ActiveX1(parent); if (key == "ActiveX2") return new ActiveX2(parent); return 0; } const QMetaObject *ActiveQtFactory::metaObject(const QString &key) const { if (key == "ActiveX1") return &ActiveX1::staticMetaObject; if (key == "ActiveX2") return &ActiveX2::staticMetaObject; } QUuid ActiveQtFactory::classID(const QString &key) const { if (key == "ActiveX1") return "{01234567-89AB-CDEF-0123-456789ABCDEF}"; ... return QUuid(); } QUuid ActiveQtFactory::interfaceID(const QString &key) const { if (key == "ActiveX1") return "{01234567-89AB-CDEF-0123-456789ABCDEF}"; ... return QUuid(); } QUuid ActiveQtFactory::eventsID(const QString &key) const { if (key == "ActiveX1") return "{01234567-89AB-CDEF-0123-456789ABCDEF}"; ... return QUuid(); } QAXFACTORY_EXPORT( ActiveQtFactory, // factory class "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID "{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID )
If you use the Q_CLASSINFO()
macro to provide the unique identifiers or other attributes for your class you can use the QAXFACTORY_BEGIN()
, QAXCLASS()
and QAXFACTORY_END()
macros to expose one or more classes as COM objects.
QAXFACTORY_BEGIN( "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID "{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID ) QAXCLASS(Class1) QAXCLASS(Class2) QAXFACTORY_END()
Only one QAxFactory implementation may be instantiated and exported by an ActiveX server application. This instance is accessible through the global qAxFactory() function.
A factory can also reimplement the registerClass() and unregisterClass() functions to set additional flags for an ActiveX control in the registry. To limit the number of methods or properties a widget class exposes from its parent classes reimplement exposeToSuperClass().
See also QAxAggregated, QAxBindable, and ActiveQt Framework.
Macro Documentation
QAXCLASS(Class)
This macro adds a creatable COM class Class to the QAxFactory declared with the QAXFACTORY_BEGIN() macro.
See also QAXFACTORY_BEGIN(), QAXTYPE(), QAXFACTORY_END(), and Q_CLASSINFO().
QAXFACTORY_BEGIN(IDTypeLib, IDApp)
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.
QAXFACTORY_BEGIN( "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID "{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID ) QAXCLASS(Class1) QAXCLASS(Class2) QAXFACTORY_END()
QAXFACTORY_END
Completes the QAxFactory declaration started with the QAXFACTORY_BEGIN() macro.
See also QAXFACTORY_BEGIN(), QAXCLASS(), and QAXTYPE().
QAXFACTORY_EXPORT(Class, LibID, AppID)
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.
QAXFACTORY_EXPORT( MyFactory, // factory class "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID "{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID )
See also QAXFACTORY_BEGIN().
QAXTYPE(Class)
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(), and Q_CLASSINFO().