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

QPluginManager Class Reference

The QPluginManager class provides basic functions to access a certain kind of functionality in libraries. More...

#include <qpluginmanager.h>

List of all member functions.

Public Members


Detailed Description

The QPluginManager class provides basic functions to access a certain kind of functionality in libraries.

A common usage of components is to extend the existing functionality in an application using plugins. The application defines interfaces that abstract a certain group of functionality, and a plugin provides a specialized implementation of one or more of those interfaces.

The QPluginManager template has to be instantiated with an interface definition and the IID for this interface.

  QPluginManager<MyPluginInterface> *manager = new QPluginManager<MyPluginInterface>( IID_MyPluginInterface );
  

It searches a specified directory for all shared libraries, queries for components that implement the specific interface and reads information about the features the plugin wants to add to the application. The component can provide the set of features provided by implementing either the QFeatureListInterface or the QComponentInformationInterface. The strings returned by the implementations of

  QStringList QFeatureListInterface::featureList() const
  

or

  QString QComponentInformationInterface::name() const
  

respectively, can then be used to access the component that provides the requested feature:

  MyPluginInterface *iface;
  manager->queryInterface( "feature", &iface );
  if ( iface )
      iface->execute( "feature" );
  

The application can use a QPluginManager instance to create parts of the user interface based on the list of features found in plugins:

  QPluginManager<MyPluginInterface> *manager = new QPluginManager<MyPluginInterface>( IID_ImageFilterInterface );
  manager->addLibraryPath(...);

  QStringList features = manager->featureList();
  for ( QStringList::Iterator it = features.begin(); it != features.end(); ++it ) {
      MyPluginInterface *iface;
      manager->queryInterface( *it, &iface );

      // use QAction to provide toolbuttons and menuitems for each feature...
  }
  

See also Component Model.


Member Function Documentation

QPluginManager::QPluginManager ( const QUuid & id, const QString & path = QString::null, QLibrary::Policy pol = QLibrary::Delayed, bool cs = TRUE )

Creates an QPluginManager for interfaces id that will load all shared library files in path, setting the default policy to pol. If cs is, FALSE the manager will handle feature strings case insensitive.

Warning: Setting the cs flag to FALSE requires that components also convert to lower case when comparing with passed strings, so this has to be handled with care and documented very well.

The pol parameter is propagated to the QLibrary object created for each library.

QLibrary * QPluginManager::addLibrary ( const QString & file ) [virtual]

Tries to load the library file, adds the library to the managed list and returns the created QLibrary object if successful, otherwise returns 0. If there is already a QLibrary object for file, this object will be returned. The library will stay in memory if the default policy is Immediately, otherwise it gets unloaded again.

Note that file does not have to include the platform dependent file extension.

See also removeLibrary() and addLibraryPath().

void QPluginManager::addLibraryPath ( const QString & path )

Calls addLibrary for all shared library files in path. The current library policy will be used for all new QLibrary objects.

See also addLibrary() and setDefaultPolicy().

QLibrary::Policy QPluginManager::defaultPolicy () const

Returns the current default policy.

See also setDefaultPolicy().

QStringList QPluginManager::featureList () const

Returns a list of all features provided by the interfaces managed by this interface manager.

See also library() and queryInterface().

QLibrary * QPluginManager::library ( const QString & feature ) const

Returns a pointer to the QLibrary providing feature.

See also featureList().

QRESULT QPluginManager::queryInterface ( const QString & feature, Type ** iface ) const

Sets iface to point to the interface providing feature.

See also featureList() and library().

bool QPluginManager::removeLibrary ( const QString & file ) [virtual]

Removes the library file from the managed list and returns TRUE if the library could be unloaded, otherwise returns FALSE.

Warning: The QLibrary object for this file will be destroyed.

See also addLibrary().

void QPluginManager::setDefaultPolicy ( QLibrary::Policy pol )

Sets the default policy for this plugin manager to pol. The default policy is propagated to all newly created QLibrary objects.

See also defaultPolicy().


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


Copyright © 2001 TrolltechTrademarks
Qt version 3.0.0-beta5