Classes - Annotated - Tree - Functions - Home - Structure

QUnknownInterface Class Reference

The API for this class is under development and is subject to change.
We do not recommend the use of this class for production work at this time.

The QUnknownInterface class is the base class for all interfaces of the Qt Component Model. More...

#include <qcom.h>

Inherited by QComponentInterface, QComponentFactoryInterface, QLibraryInterface, QFeatureListInterface and QComponentServerInterface.

List of all member functions.

Public Members


Detailed Description

The QUnknownInterface class is the base class for all interfaces of the Qt Component Model.

All interfaces in the component object model are derived from the QUnknownInterface. This interface provides control of the object's lifetime and the ability to navigate a component implementing multiple interfaces. The object's lifetime is controlled using a reference count that is increased and decreased using the functions addRef and release, respectively. The queryInterface function determines whether the component supports a specific interface. For every interface a Unique Universal Identifier (UUID) is provided to identify requests for the interface. In Qt, this identifier is wrapped in the QUuid class that provides convenience operators for comparison and copying.


Member Function Documentation

ulong QUnknownInterface::addRef () [virtual]

Increases the reference counter for this interface by one and returns the old reference count.

Example:

  int MyComponent::addRef()
  {
      return ref++;
  }
  

This function must be called when this interface is returned as a result of a queryInterface() call. It should be called for every new copy of a pointer to this interface.

See also queryInterface() and release().

QRESULT QUnknownInterface::queryInterface ( const QUuid & request, QUnknownInterface ** iface ) [virtual]

Returns a pointer to an interface specified with request, or NULL if this interface can't provide the requested interface. An implementation of this function must call addRef() on the pointer it returns.

Example:

  QRESULT MyComponent::queryInterface( const QUuid &request, QUnknownInterface** iface )
  {
      if ( request == IID_QUnknownInterface )
          *iface = this;
      else if ( request == IID_... )
          *iface = (...*)this;
      ...

      if ( *iface )
          (*iface)->addRef();
     return;
  }
  

There are five requirements for implementations of queryInterface:

See also addRef() and release().

ulong QUnknownInterface::release () [virtual]

Decreases the reference count for this interface by one and returns the new reference count. If the reference count falls to 0, the object is freed from memory.

Example:

  int MyComponent::release()
  {
      if ( !--ref ) {
          delete this;
          return 0;
      }
      return ref;
  }
  

This function should be called whenever a copy of a pointer to this interface is no longer needed.

See also addRef().


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.


Copyright © 2001 TrolltechTrademarks
Qt version 3.0.0-beta1-beta1