Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QAxFactory Class Reference

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

 #include <QAxFactory>

Inherits: QObject.

Public Types

enum ServerType { SingleInstance, MultipleInstances }

Public Functions

QAxFactory ( const QUuid & libid, const QUuid & appid )
virtual ~QAxFactory ()
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
  • 29 public functions inherited from QObject

Static Public Members

bool isServer ()
bool registerActiveObject ( QObject * object )
QString serverDirPath ()
QString serverFilePath ()
bool startServer ( ServerType type = MultipleInstances )
bool stopServer ()
  • 5 static public members inherited from QObject

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 from QObject
  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject
  • 7 protected functions inherited from QObject

Detailed Description

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

If your server supports just a single COM object, you can use a default factory implementation through the QAXFACTORY_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 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.

Member Type Documentation

enum QAxFactory::ServerType

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

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 ( const QUuid & libid, const QUuid & appid )

Constructs a QAxFactory object that returns libid and appid in the implementation of the respective interface functions.

QAxFactory::~QAxFactory () [virtual]

Destroys the QAxFactory object.

QUuid QAxFactory::appID () const [virtual]

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

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

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".

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

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

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

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

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 [virtual]

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 [virtual]

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.

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

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

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

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

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

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 [virtual]

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".

bool QAxFactory::isServer () [static]

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 [virtual]

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.

const QMetaObject * QAxFactory::metaObject ( const QString & key ) const [pure virtual]

Reimplement this function to return the QMetaObject corresponding to key, or 0 if this factory doesn't support the value of key.

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

Registers the 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 [virtual]

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.

See also QSettings.

QString QAxFactory::serverDirPath () [static]

Returns the directory that contains the server binary.

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

QString QAxFactory::serverFilePath () [static]

Returns the file path of the server binary.

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

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

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 set to MultipleInstances if the server executable has been started with the -activex command line parameter. To switch to SingleInstance, call

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

in your own main() entry point function.

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

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

bool QAxFactory::stopServer () [static]

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 [virtual]

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

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

Unregisters any additional values for the class key from the system registry using the settings object.

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

See also registerClass() and QSettings.

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

Reimplement this function to return true if 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.

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_DEFAULT ( Class, ClassID, InterfaceID, EventID, LibID, AppID )

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"

 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 also QAXFACTORY_EXPORT() and QAXFACTORY_BEGIN().

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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 27
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web