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  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QLibrary Class Reference

The QLibrary class provides a wrapper for handling shared libraries. More...

All the functions in this class are reentrant when Qt is built with thread support.

#include <qlibrary.h>

List of all member functions.

Public Members

Static Public Members

  • void * resolve ( const QString & filename, const char * symb )

Detailed Description

The QLibrary class provides a wrapper for handling shared libraries.

An instance of a QLibrary object can handle a single shared library and provide access to the functionality in the library in a platform independent way. If the library is a component server, QLibrary provides access to the exported component and can directly query this component for interfaces.

QLibrary ensures that the shared library is loaded and stays in memory whilst it is in use. QLibrary can also unload the library on destruction and release unused resources.

A typical use of QLibrary is to resolve an exported symbol in a shared object, and to call the function that this symbol represents. This is called "explicit linking" in contrast to "implicit linking", which is done by the link step in the build process when linking an executable against a library.

The following code snippet loads a library, resolves the symbol "mysymbol", and calls the function if everything succeeded. If something went wrong, e.g. the library file does not exist or the symbol is not defined, the function pointer will be 0 and won't be called. When the QLibrary object is destroyed the library will be unloaded, making all references to memory allocated in the library invalid.

    typedef void (*MyPrototype)();
    MyPrototype myFunction;

    QLibrary myLib( "mylib" );
    myFunction = (MyProtoype) myLib.resolve( "mysymbol" );
    if ( myFunction ) {
        myFunction();
    }
    

See also Plugins.


Member Function Documentation

QLibrary::QLibrary ( const QString & filename )

Creates a QLibrary object for the shared library filename. The library will be unloaded in the destructor.

Note that filename does not need to include the (platform specific) file extension, so calling

    QLibrary lib( "mylib" );
    
is equivalent to calling
    QLibrary lib( "mylib.dll" );
    
on Windows, and
    QLibrary lib( "libmylib.so" );
    
on Unix. Specifying the extension is not recommended, since doing so introduces a platform dependency.

If filename does not include a path, the library loader will look for the file in the platform specific search paths.

See also load(), unload(), and setAutoUnload().

QLibrary::~QLibrary () [virtual]

Deletes the QLibrary object.

The library will be unloaded if autoUnload() is TRUE (the default), otherwise it stays in memory until the application exits.

See also unload() and setAutoUnload().

bool QLibrary::autoUnload () const

Returns TRUE if the library will be automatically unloaded when this wrapper object is destructed; otherwise returns FALSE. The default is TRUE.

See also setAutoUnload().

bool QLibrary::isLoaded () const

Returns TRUE if the library is loaded; otherwise returns FALSE.

See also unload().

QString QLibrary::library () const

Returns the filename of the shared library this QLibrary object handles, including the platform specific file extension.

For example:

    QLibrary lib( "mylib" );
    QString str = lib.library();
    
will set str to "mylib.dll" on Windows, and "libmylib.so" on Linux.

bool QLibrary::load ()

Loads the library. Since resolve() always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the library loaded in advance, in which case you would use this function.

void * QLibrary::resolve ( const char * symb )

Returns the address of the exported symbol symb. The library is loaded if necessary. The function returns 0 if the symbol could not be resolved or the library could not be loaded.

    typedef int (*avgProc)( int, int );

    avgProc avg = (avgProc) library->resolve( "avg" );
    if ( avg )
        return avg( 5, 8 );
    else
        return -1;
    

void * QLibrary::resolve ( const QString & filename, const char * symb ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Loads the library filename and returns the address of the exported symbol symb. Note that like the constructor, filename does not need to include the (platform specific) file extension. The library remains loaded until the process exits.

The function returns 0 if the symbol could not be resolved or the library could not be loaded.

This function is useful only if you want to resolve a single symbol, e.g. a function pointer from a specific library once:

    typedef void (*FunctionType)();
    static FunctionType *ptrFunction = 0;
    static bool triedResolve = FALSE;
    if ( !ptrFunction && !triedResolve )
        ptrFunction = QLibrary::resolve( "mylib", "mysymb" );

    if ( ptrFunction )
        ptrFunction();
    else
        ...
    

If you want to resolve multiple symbols, use a QLibrary object and call the non-static version of resolve().

See also

void QLibrary::setAutoUnload ( bool enabled )

If enabled is TRUE (the default), the wrapper object is set to automatically unload the library upon destruction. If enabled is FALSE, the wrapper object is not unloaded unless you explicitly call unload().

See also autoUnload().

bool QLibrary::unload () [virtual]

Unloads the library and returns TRUE if the library could be unloaded; otherwise returns FALSE.

This function is called by the destructor if autoUnload() is enabled.

See also resolve().


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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 9
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le Qt Quarterly au hasard

Logo

Écrire un périphérique personnalisé d'E/S

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. 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 3.2
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