Movatterモバイル変換


[0]ホーム

URL:


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

Menu

Qt Documentation

QAxFactory Class

TheQAxFactory class defines a factory for the creation of COM components.More...

Header:#include <QAxFactory>
Inherits:QObject

Public Types

enumServerType { SingleInstance, MultipleInstances }

Public Functions

QAxFactory(const QUuid & libid, const QUuid & appid)
virtual~QAxFactory()
virtual QUuidappID() const
virtual QUuidclassID(const QString & key) const
virtual QObject *createObject(const QString & key) = 0
virtual boolcreateObjectWrapper(QObject * object, IDispatch ** wrapper)
virtual QUuideventsID(const QString & key) const
virtual QStringexposeToSuperClass(const QString & key) const
virtual QStringListfeatureList() const = 0
virtual boolhasStockEvents(const QString & key) const
virtual QUuidinterfaceID(const QString & key) const
virtual boolisService() const
virtual const QMetaObject *metaObject(const QString & key) const = 0
virtual voidregisterClass(const QString & key, QSettings * settings) const
virtual boolstayTopLevel(const QString & key) const
virtual QUuidtypeLibID() const
virtual voidunregisterClass(const QString & key, QSettings * settings) const
virtual boolvalidateLicenseKey(const QString & key, const QString & licenseKey) const
  • 29 public functions inherited fromQObject

Static Public Members

boolisServer()
boolregisterActiveObject(QObject * object)
QStringserverDirPath()
QStringserverFilePath()
boolstartServer(ServerType type = MultipleInstances)
boolstopServer()
  • 7 static public members inherited fromQObject

Macros

QAXCLASS( Class)
QAXFACTORY_BEGIN( IDTypeLib, IDApp)
QAXFACTORY_DEFAULT( Class, ClassID, InterfaceID, EventID, LibID, AppID)
QAXFACTORY_END()
QAXFACTORY_EXPORT( Class, LibID, AppID)
QAXTYPE( Class)

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 1 signal inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQAxFactory class defines a factory for the creation of COM components.

Implement this factory once in your COM server to provide information about the components the server can create. SubclassQAxFactory and implement the pure virtual functions in any implementation file (e.g. main.cpp), and export the factory using theQAXFACTORY_EXPORT() macro.

QStringList ActiveQtFactory::featureList()const{QStringList list;    list<<"ActiveX1";    list<<"ActiveX2";return list;}QObject*ActiveQtFactory::createObject(constQString&key){if (key=="ActiveX1")returnnew ActiveX1(parent);if (key=="ActiveX2")returnnew ActiveX2(parent);return0;}constQMetaObject*ActiveQtFactory::metaObject(constQString&key)const{if (key=="ActiveX1")return&ActiveX1::staticMetaObject;if (key=="ActiveX2")return&ActiveX2::staticMetaObject;}QUuid ActiveQtFactory::classID(constQString&key)const{if (key=="ActiveX1")return"{01234567-89AB-CDEF-0123-456789ABCDEF}";...returnQUuid();}QUuid ActiveQtFactory::interfaceID(constQString&key)const{if (key=="ActiveX1")return"{01234567-89AB-CDEF-0123-456789ABCDEF}";...returnQUuid();}QUuid ActiveQtFactory::eventsID(constQString&key)const{if (key=="ActiveX1")return"{01234567-89AB-CDEF-0123-456789ABCDEF}";...returnQUuid();}QAXFACTORY_EXPORT(    ActiveQtFactory,// factory class"{01234567-89AB-CDEF-0123-456789ABCDEF}",// type library ID"{01234567-89AB-CDEF-0123-456789ABCDEF}"// application ID)

If you use theQ_CLASSINFO() macro to provide the unique identifiers or other attributes for your class you can use theQAXFACTORY_BEGIN(),QAXCLASS() andQAXFACTORY_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()

If your server supports just a single COM object, you can use a default factory implementation through theQAXFACTORY_DEFAULT() macro.

#include <qapplication.h>#include <qaxfactory.h>#include "theactivex.h"QAXFACTORY_DEFAULT(    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)

Only oneQAxFactory 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 theregisterClass() andunregisterClass() 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 reimplementexposeToSuperClass().

See alsoQAxAggregated,QAxBindable, andActiveQt Framework.

Member Type Documentation

enum QAxFactory::ServerType

This enum specifies the different types of servers that can be started withstartServer.

ConstantValueDescription
QAxFactory::SingleInstance0The server process can create only one instance of each exported class. COM starts a new process for each request. This is typically used in servers that export only one creatable class.
QAxFactory::MultipleInstances1The server can create multiple instances of each exported class. This is the default. All instances will live in the same thread, and will share static resources.

Member Function Documentation

QAxFactory::QAxFactory(constQUuid & libid, constQUuid & appid)

Constructs aQAxFactory object that returnslibid andappid in the implementation of the respective interface functions.

[virtual]QAxFactory::~QAxFactory()

Destroys theQAxFactory object.

[virtual]QUuid QAxFactory::appID() const

Reimplement this function to return the ActiveX server's application identifier.

[virtual]QUuid QAxFactory::classID(constQString & key) const

Reimplement this function to return the class identifier for eachkey returned by thefeatureList() implementation, or an emptyQUuid if this factory doesn't support the value ofkey.

The default implementation interpretskey as the class name, and returns the value of theQ_CLASSINFO() entry "ClassID".

[pure virtual]QObject * QAxFactory::createObject(constQString & key)

Reimplement this function to return a new object forkey, or 0 if this factory doesn't support the value ofkey.

If the object returned is aQWidget it will be exposed as an ActiveX control, otherwise the returned object will be exposed as a simple COM object.

[virtual]bool QAxFactory::createObjectWrapper(QObject * object,IDispatch ** wrapper)

Reimplement this function to provide the COM object forobject inwrapper. Return true if the function was successful; otherwise return false.

The default implementation creates a generic automation wrapper based on the meta object information ofobject.

[virtual]QUuid QAxFactory::eventsID(constQString & key) const

Reimplement this function to return the identifier of the event interface for eachkey returned by thefeatureList() implementation, or an emptyQUuid if this factory doesn't support the value ofkey.

The default implementation interpretskey as the class name, and returns the value of theQ_CLASSINFO() entry "EventsID".

[virtual]QString QAxFactory::exposeToSuperClass(constQString & key) const

Reimplement this function to return the name of the super class ofkey up to which methods and properties should be exposed by the ActiveX control.

The default implementation interpretskey as the class name, and returns the value of theQ_CLASSINFO() entry "ToSuperClass". If no such value is set the null-string is returned, and the functions and properties of all the super classes includingQWidget will be exposed.

To only expose the functions and properties of the class itself, reimplement this function to returnkey.

[pure virtual]QStringList QAxFactory::featureList() const

Reimplement this function to return a list of the widgets (class names) supported by this factory.

[virtual]bool QAxFactory::hasStockEvents(constQString & key) const

Reimplement this function to return true if the ActiveX controlkey should support the standard ActiveX events

  • Click
  • DblClick
  • KeyDown
  • KeyPress
  • KeyUp
  • MouseDown
  • MouseUp
  • MouseMove

The default implementation interpretskey as the class name, and returns true if the value of theQ_CLASSINFO() entry "StockEvents" is "yes". Otherwise this function returns false.

[virtual]QUuid QAxFactory::interfaceID(constQString & key) const

Reimplement this function to return the interface identifier for eachkey returned by thefeatureList() implementation, or an emptyQUuid if this factory doesn't support the value ofkey.

The default implementation interpretskey as the class name, and returns the value of theQ_CLASSINFO() entry "InterfaceID".

[static]bool QAxFactory::isServer()

Returns true if the application has been started (by COM) as an ActiveX server, otherwise returns false.

int main(int argc,char*argv[]){QApplication app(argc, argv);if (!QAxFactory::isServer()) {// initialize for stand-alone execution    }return app.exec();}

[virtual]bool QAxFactory::isService() const

Reimplement this function to return true if the server is running as a persistent service (e.g. an NT service) and should not terminate even when all objects provided have been released.

The default implementation returns false.

[pure virtual]constQMetaObject * QAxFactory::metaObject(constQString & key) const

Reimplement this function to return theQMetaObject corresponding tokey, or 0 if this factory doesn't support the value ofkey.

[static]bool QAxFactory::registerActiveObject(QObject * object)

Registers theQObjectobject with COM as a running object, and returns true if the registration succeeded, otherwise returns false. The object is unregistered automatically when it is destroyed.

This function should only be called if the application has been started by the user (i.e. not by COM to respond to a request), and only for one object, usually the toplevel object of the application's object hierarchy.

This function does nothing and returns false if the object's class info for "RegisterObject" is not set to "yes", or if the server is an in-process server.

[virtual]void QAxFactory::registerClass(constQString & key,QSettings * settings) const

Registers additional values for the classkey in the system registry using thesettings object. The standard values have already been registered by the framework, but additional values, e.g. implemented categories, can be added in an implementation of this function.

settings->setValue("/CLSID/"+ classID(key)+"/Implemented Categories/"+"/{00000000-0000-0000-000000000000}/.",QString());

If you reimplement this function you must also reimplementunregisterClass() to remove the additional registry values.

See alsoQSettings.

[static]QString QAxFactory::serverDirPath()

Returns the directory that contains the server binary.

For out-of-process servers this is the same asQApplication::applicationDirPath(). For in-process servers that function returns the directory that contains the hosting application.

[static]QString QAxFactory::serverFilePath()

Returns the file path of the server binary.

For out-of-process servers this is the same asQApplication::applicationFilePath(). For in-process servers that function returns the file path of the hosting application.

[static]bool QAxFactory::startServer(ServerType type = MultipleInstances)

Starts the COM server withtype and returns true if successful, otherwise returns false.

Calling this function if the server is already running (or for an in-process server) does nothing and returns true.

The server is started automatically withtype set toMultipleInstances if the server executable has been started with the-activex command line parameter. To switch toSingleInstance, call

if (QAxFactory::isServer()) {QAxFactory::stopServer();QAxFactory::startServer(QAxFactory::SingleInstance);}

in your own main() entry point function.

[virtual]bool QAxFactory::stayTopLevel(constQString & key) const

Reimplement this function to return true if the ActiveX controlkey should be a top level window, e.g. a dialog. The default implementation returns false.

[static]bool QAxFactory::stopServer()

Stops the COM server and returns true if successful, otherwise returns false.

Calling this function if the server is not running (or for an in-process server) does nothing and returns true.

Stopping the server will not invalidate existing objects, but no new objects can be created from the existing server process. Usually COM will start a new server process if additional objects are requested.

The server is stopped automatically when the main() function returns.

[virtual]QUuid QAxFactory::typeLibID() const

Reimplement this function to return the ActiveX server's type library identifier.

[virtual]void QAxFactory::unregisterClass(constQString & key,QSettings * settings) const

Unregisters any additional values for the classkey from the system registry using thesettings object.

settings->remove("/CLSID/"+ classID(key)+"/Implemented Categories"+"/{00000000-0000-0000-000000000000}/.");

See alsoregisterClass() andQSettings.

[virtual]bool QAxFactory::validateLicenseKey(constQString & key, constQString & licenseKey) const

Reimplement this function to return true iflicenseKey is a valid license for the classkey, or if the current machine is licensed.

The default implementation returns true if the classkey is not licensed (ie. noQ_CLASSINFO() attribute "LicenseKey"), or iflicenseKey matches the value of the "LicenseKey" attribute, or if the machine is licensed through a .LIC file with the same filename as this COM server.

Macro Documentation

QAXCLASS( Class)

This macro adds a creatable COM classClass to theQAxFactory declared with theQAXFACTORY_BEGIN() macro.

See alsoQAXFACTORY_BEGIN(),QAXTYPE(),QAXFACTORY_END(), andQ_CLASSINFO().

QAXFACTORY_BEGIN( IDTypeLib, IDApp)

This macro can be used to export multipleQObject classes through an implicitly declaredQAxFactory implementation. AllQObject classes have to declare the ClassID, InterfaceID and EventsID (if applicable) through theQ_CLASSINFO() macro. All declarations will be in a type library with the idIDTypeLib, and if the server is an executable server then it will have the application idIDApp.

This macro needs to be used together with theQAXCLASS(),QAXTYPE() andQAXFACTORY_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_DEFAULT( Class, ClassID, InterfaceID, EventID, LibID, AppID)

This macro can be used to export a singleQObject subclassClass a this COM server through an implicitly declaredQAxFactory implementation.

This macro exports the classClass as a COM coclass with the CLSIDClassID. The properties and slots will be declared through a COM interface with the IIDInterfaceID, and signals will be declared through a COM event interface with the IIDEventID. All declarations will be in a type library with the idLibID, and if the server is an executable server then it will have the application idAppID.

#include <qaxfactory.h>#include "theactivex.h"QAXFACTORY_DEFAULT(    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 alsoQAXFACTORY_EXPORT() andQAXFACTORY_BEGIN().

QAXFACTORY_END()

Completes theQAxFactory declaration started with theQAXFACTORY_BEGIN() macro.

See alsoQAXFACTORY_BEGIN(),QAXCLASS(), andQAXTYPE().

QAXFACTORY_EXPORT( Class, LibID, AppID)

This macro can be used to export aQAxFactory implementationClass from a COM server. All declarations will be in a type library with the idLibID, and if the server is an executable server then it will have the application idAppID.

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

See alsoQAXFACTORY_BEGIN().

QAXTYPE( Class)

This macro adds a non-creatable COM classClass to theQAxFactory declared with theQAXFACTORY_BEGIN(). The classClass can be used in APIs of other COM classes exported through QAXTYPE() orQAXCLASS().

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

See alsoQAXFACTORY_BEGIN(),QAXCLASS(),QAXFACTORY_END(), andQ_CLASSINFO().

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


[8]ページ先頭

©2009-2025 Movatter.jp