| 
 QThreadStorage Class ReferenceThe QThreadStorage class provides per-thread data storage. More... All the functions in this class are thread-safe when Qt is built with thread support. #include <qthreadstorage.h> Public Members
 Detailed DescriptionThe QThreadStorage class provides per-thread data storage.
 QThreadStorage is a template class that provides per-thread data storage. Note that due to compiler limitations, QThreadStorage can only store pointers. The setLocalData() function stores a single thread-specific value for the calling thread. The data can be accessed later using the localData() functions. QThreadStorage takes ownership of the data (which must be created on the heap with new) and deletes it when the thread exits (either normally or via termination). The hasLocalData() function allows the programmer to determine if data has previously been set using the setLocalData() function. This is useful for lazy initializiation. For example, the following code uses QThreadStorage to store a single cache for each thread that calls the cacheObject() and removeFromCache() functions. The cache is automatically deleted when the calling thread exits (either normally or via termination). 
 
    QThreadStorage<QCache<SomeClass> *> caches;
    void cacheObject( const QString &key, SomeClass *object )
    {
        if ( ! caches.hasLocalData() )
            caches.setLocalData( new QCache<SomeClass> );
        caches.localData()->insert( key, object );
    }
    void removeFromCache( const QString &key )
    {
        if ( ! caches.hasLocalData() )
            return; // nothing to do
        caches.localData()->remove( key );
    }
    
 Caveats
 
 
 See also Environment Classes and Threading. Member Function Documentation
 | Publicité Best OfActualités les plus luesSemaine Mois Année 
 
   
   Le Qt Labs au hasard  Velours et QML Scene GraphLes Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article. CommunautéRessources
 Liens utilesContact
 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 ! | ||
Copyright © 2000-2012 - www.developpez.com