The QAxFactory 類定義用於創建 COM 組件的工廠。 更多...
| 頭: | #include <QAxFactory> |
| qmake: | QT += axserver |
| 繼承: | QObject |
| enum | ServerType { SingleInstance, MultipleInstances } |
| QAxFactory (const QUuid & libid , const QUuid & appid ) | |
| virtual | ~QAxFactory () override |
| virtual QUuid | appID () const |
| virtual QUuid | classID (const QString & key ) const |
| virtual QObject * | createObject (const QString & key ) = 0 |
| virtual bool | createObjectWrapper (QObject * object , IDispatch ** wrapper ) |
| virtual QUuid | eventsID (const QString & key ) const |
| virtual QString | exposeToSuperClass (const QString & key ) const |
| virtual QStringList | featureList () const = 0 |
| virtual bool | hasStockEvents (const QString & key ) const |
| virtual QUuid | interfaceID (const QString & key ) const |
| virtual bool | isService () const |
| virtual const QMetaObject * | metaObject (const QString & key ) const = 0 |
| virtual void | registerClass (const QString & key , QSettings * settings ) const |
| virtual bool | stayTopLevel (const QString & key ) const |
| virtual QUuid | typeLibID () const |
| virtual void | unregisterClass (const QString & key , QSettings * settings ) const |
| virtual bool | validateLicenseKey (const QString & key , const QString & licenseKey ) const |
| bool | isServer () |
| bool | registerActiveObject (QObject * object ) |
| QString | serverDirPath () |
| QString | serverFilePath () |
| bool | startServer (QAxFactory::ServerType type = MultipleInstances) |
| bool | stopServer () |
| QAXCLASS ( Class ) | |
| QAXFACTORY_BEGIN ( IDTypeLib , IDApp ) | |
| QAXFACTORY_DEFAULT ( Class , ClassID , InterfaceID , EventID , LibID , AppID ) | |
| QAXFACTORY_END | |
| QAXFACTORY_EXPORT ( Class , LibID , AppID ) | |
| QAXTYPE ( Class ) |
The QAxFactory 類定義用於創建 COM 組件的工廠。
一旦在 COM 服務器中實現此工廠,就能提供服務器可以創建的有關組件信息。子類
QAxFactory
並在任何實現文件 (如 main.cpp) 中實現純虛擬函數,和導齣工廠使用
QAXFACTORY_EXPORT()
宏。
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 )
若使用
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()
If your server supports just a single COM object, you can use a default factory implementation through the
QAXFACTORY_DEFAULT()
宏。
#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 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 () 和 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 ().
另請參閱 QAxAggregated , QAxBindable ,和 ActiveQt 框架 .
This enum specifies the different types of servers that can be started with startServer .
| 常量 | 值 | 描述 |
|---|---|---|
QAxFactory::SingleInstance
|
0
|
The 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::MultipleInstances
|
1
|
The 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. |
構造 QAxFactory 對象返迴 libid and appid 在各自接口函數的實現中。
[override virtual]
QAxFactory::
~QAxFactory
()
銷毀 QAxFactory 對象。
[虛擬]
QUuid
QAxFactory::
appID
() const
Reimplement this function to return the ActiveX server's application identifier.
[虛擬]
QUuid
QAxFactory::
classID
(const
QString
&
key
) const
Reimplement this function to return the class identifier for each key returned by the featureList () implementation, or an empty QUuid if this factory doesn't support the value of key .
The default implementation interprets key as the class name, and returns the value of the Q_CLASSINFO () entry "ClassID".
[pure virtual]
QObject
*QAxFactory::
createObject
(const
QString
&
key
)
重實現此函數以返迴新對象為 key ,或 0 若此工廠不支持值對於 key .
若返迴對象是 QWidget 它會被暴露成 ActiveX 控件,否則返迴對象將被暴露成簡單 COM 對象。
[虛擬]
bool
QAxFactory::
createObjectWrapper
(
QObject
*
object
,
IDispatch
**
wrapper
)
Reimplement this function to provide the COM object for object in wrapper . Return true if the function was successful; otherwise return false.
The default implementation creates a generic automation wrapper based on the meta object information of object .
[虛擬]
QUuid
QAxFactory::
eventsID
(const
QString
&
key
) const
Reimplement this function to return the identifier of the event interface for each key returned by the featureList () implementation, or an empty QUuid if this factory doesn't support the value of key .
The default implementation interprets key as the class name, and returns the value of the Q_CLASSINFO () entry "EventsID".
[虛擬]
QString
QAxFactory::
exposeToSuperClass
(const
QString
&
key
) const
Reimplement this function to return the name of the super class of key up to which methods and properties should be exposed by the ActiveX control.
The default implementation interprets
key
as the class name, and returns the value of the
Q_CLASSINFO()
entry "ToSuperClass". If no such value is set the null-string is returned, and the functions and properties of all the super classes including
QWidget
will be exposed.
To only expose the functions and properties of the class itself, reimplement this function to return key .
[pure virtual]
QStringList
QAxFactory::
featureList
() const
Reimplement this function to return a list of the widgets (class names) supported by this factory.
[虛擬]
bool
QAxFactory::
hasStockEvents
(const
QString
&
key
) const
重實現此函數以返迴 true 若 ActiveX 控件 key 應支持標準 ActiveX 事件
The default implementation interprets
key
as the class name, and returns true if the value of the
Q_CLASSINFO()
entry "StockEvents" is "yes". Otherwise this function returns false.
[虛擬]
QUuid
QAxFactory::
interfaceID
(const
QString
&
key
) const
Reimplement this function to return the interface identifier for each key returned by the featureList () implementation, or an empty QUuid if this factory doesn't support the value of key .
The default implementation interprets key as the class name, and returns the value of the Q_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(); }
[虛擬]
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.
默認實現返迴 false。
[pure virtual]
const
QMetaObject
*QAxFactory::
metaObject
(const
QString
&
key
) const
重實現此函數以返迴 QMetaObject 對應 key ,或 0 若此工廠不支持值對於 key .
[static]
bool
QAxFactory::
registerActiveObject
(
QObject
*
object
)
注冊 QObject object 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.
[虛擬]
void
QAxFactory::
registerClass
(const
QString
&
key
,
QSettings
*
settings
) const
Registers additional values for the class key in the system registry using the settings 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 reimplement unregisterClass () to remove the additional registry values.
另請參閱 QSettings .
[static]
QString
QAxFactory::
serverDirPath
()
Returns the directory that contains the server binary.
For out-of-process servers this is the same as QCoreApplication::applicationDirPath (). For in-process servers that function returns the directory that contains the hosting application.
[static]
QString
QAxFactory::
serverFilePath
()
返迴服務器二進製的文件路徑。
For out-of-process servers this is the same as QCoreApplication::applicationFilePath (). For in-process servers that function returns the file path of the hosting application.
[static]
bool
QAxFactory::
startServer
(
QAxFactory::ServerType
type
= MultipleInstances)
Starts the COM server with type 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 with
type
設為
MultipleInstances
if the server executable has been started with the
-activex
command line parameter. To switch to
SingleInstance
,調用
if (QAxFactory::isServer()) { QAxFactory::stopServer(); QAxFactory::startServer(QAxFactory::SingleInstance); }
in your own main() entry point function.
[虛擬]
bool
QAxFactory::
stayTopLevel
(const
QString
&
key
) const
重實現此函數以返迴 true 若 ActiveX 控件 key 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.
[虛擬]
QUuid
QAxFactory::
typeLibID
() const
Reimplement this function to return the ActiveX server's type library identifier.
[虛擬]
void
QAxFactory::
unregisterClass
(const
QString
&
key
,
QSettings
*
settings
) const
Unregisters any additional values for the class key from the system registry using the settings 對象。
settings->remove("/CLSID/" + classID(key) + "/Implemented Categories" + "/{00000000-0000-0000-000000000000}/.");
另請參閱 registerClass () 和 QSettings .
[虛擬]
bool
QAxFactory::
validateLicenseKey
(const
QString
&
key
, const
QString
&
licenseKey
) const
重實現此函數以返迴 true 若 licenseKey is a valid license for the class key , or if the current machine is licensed.
The default implementation returns true if the class
key
is not licensed (ie. no
Q_CLASSINFO()
attribute "LicenseKey"), or if
licenseKey
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.
此宏添加可創建 COM 類 Class 到 QAxFactory 聲明采用 QAXFACTORY_BEGIN () 宏。
另請參閱 QAXFACTORY_BEGIN (), QAXTYPE (), QAXFACTORY_END (),和 Q_CLASSINFO ().
此宏可以用於導齣多個 QObject 類透過隱式聲明 QAxFactory 實現。所有 QObject 類必須聲明 ClassID、InterfaceID 和 EventsID (若適用) 透過 Q_CLASSINFO () 宏。類型庫中的所有聲明將具有 ID IDTypeLib ,且若服務器是可執行服務器那麼它將擁有應用程序 ID IDApp .
需要一起使用此宏同 QAXCLASS (), QAXTYPE () 和 QAXFACTORY_END () 宏。
QAXFACTORY_BEGIN(
"{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID
)
QAXCLASS(Class1)
QAXCLASS(Class2)
QAXFACTORY_END()
此宏可以用於導齣單個 QObject 子類 Class 這種 COM 服務器透過隱式聲明 QAxFactory 實現。
此宏導齣類 Class 作為 COM 輔助類采用 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 ,且若服務器是可執行服務器那麼它將擁有應用程序 ID AppID .
#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 )
另請參閱 QAXFACTORY_EXPORT () 和 QAXFACTORY_BEGIN ().
完成 QAxFactory 聲明開始采用 QAXFACTORY_BEGIN () 宏。
另請參閱 QAXFACTORY_BEGIN (), QAXCLASS (),和 QAXTYPE ().
此宏可以用於導齣 QAxFactory 實現 Class 從 COM 服務器。類型庫中的所有聲明將具有 ID LibID ,且若服務器是可執行服務器那麼它將擁有應用程序 ID AppID .
QAXFACTORY_EXPORT(
MyFactory, // factory class
"{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
"{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID
)
另請參閱 QAXFACTORY_BEGIN ().
此宏添加不可創建 COM 類 Class 到 QAxFactory 聲明采用 QAXFACTORY_BEGIN ()。類 Class can be used in APIs of other COM classes exported through QAXTYPE() or QAXCLASS ().
實例化的類型 Class can only be retrieved using APIs of already instantiated objects.
另請參閱 QAXFACTORY_BEGIN (), QAXCLASS (), QAXFACTORY_END (),和 Q_CLASSINFO ().