Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QAxFactory Class Reference
[QAxServer module]

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

This class is part of the Qt ActiveQt Extension.

`#include <qaxfactory.h>`

List of all member functions.

## Public Members

- QAxFactory ( const QUuid & libid, const QUuid & appid )
- virtual ~QAxFactory ()
- virtual QStringList featureList () const = 0
- virtual QWidget * create ( const QString & key, QWidget * parent = 0, const char * name = 0 ) = 0
- virtual QUuid classID ( const QString & key ) const = 0
- virtual QUuid interfaceID ( const QString & key ) const = 0
- virtual QUuid eventsID ( const QString & key ) const = 0
- QUuid typeLibID () const
- QUuid appID () const
- void registerClass ( const QString & key, QSettings * settings ) const
- void unregisterClass ( const QString & key, QSettings * settings ) const
- QString exposeToSuperClass ( const QString & key ) const
- bool stayTopLevel ( const QString & key ) const
- bool hasStockEvents ( const QString & key ) const
- bool isService () const

## Static Public Members

- bool isServer ()

## Detailed Description

This class is defined in the Qt ActiveQt Extension, which can be found in the `qt/extensions` directory. It is not included in the main Qt API.

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

Implement this factory once in your ActiveX server to provide information about the components the server can create. If your server supports just a single ActiveX control, you can use the default factory implementation instead of implementing the factory yourself. Use the QAXFACTORY_DEFAULT macro in any implementation file (e.g. main.cpp) to instantiate and export the default factory:

        #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
            )

If you implement your own factory reimplement the pure virtual functions to provide the unique identifiers for the ActiveX controls, and use the QAXFACTORY_EXPORT macro to instantiate and export it:

        QStringList ActiveQtFactory::featureList() const
        {
            QStringList list;
            list << "ActiveX1";
            list << "ActiveX2";
            ...
            return list;
        }

        QWidget *ActiveQtFactory::create( const QString &key, QWidget *parent, const char *name )
        {
            if ( key == "ActiveX1" )
                return new ActiveX1( parent, name );
            if ( key == "ActiveX2" )
                return new ActiveX2( parent, name );
            ...
            return 0;
        }

        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(
            MyFactory,                                // factory class
            "{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.

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

## 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

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

### QUuid QAxFactory::classID ( const QString & key ) const`[pure 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.

### QWidget * QAxFactory::create ( const QString & key, QWidget * parent = 0, const char * name = 0 )`[pure virtual]`

Reimplement this function to return a new widget for each key returned by the featureList() implementation. Propagate parent and name to the QWidget constructor. Return 0 if this factory doesn't support the value of key.

### QUuid QAxFactory::eventsID ( const QString & key ) const`[pure 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.

### 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 returns "QWidget" which means that all 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

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 returns FALSE.

### QUuid QAxFactory::interfaceID ( const QString & key ) const`[pure 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.

### 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() // standard event processing
        }

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

### 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 registed by the framework, but additional values, e.g. implemented categories, can be added in an implementation of this function.

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

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

See also QSettings.

### bool QAxFactory::stayTopLevel ( const QString & key ) const

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.

### 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 object.

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

See also registerClass() and QSettings.

This file is part of the Qt toolkit. Copyright © 1995-2003 Trolltech. All Rights Reserved.