⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qthreadstorage.3qt

📁 Trolltech公司发布的基于C++图形开发环境
💻 3QT
字号:
'\" t.TH QThreadStorage 3qt "21 January 2005" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS.  All rights reserved.  See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQThreadStorage \- Per-thread data storage.SH SYNOPSISAll the functions in this class are thread-safe when Qt is built with thread support.</p>.PP\fC#include <qthreadstorage.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "\fBQThreadStorage\fR ()".br.ti -1c.BI "\fB~QThreadStorage\fR ()".br.ti -1c.BI "bool \fBhasLocalData\fR () const".br.ti -1c.BI "T & \fBlocalData\fR ()".br.ti -1c.BI "T \fBlocalData\fR () const".br.ti -1c.BI "void \fBsetLocalData\fR ( T data )".br.in -1c.SH DESCRIPTIONThe QThreadStorage class provides per-thread data storage..PPQThreadStorage is a template class that provides per-thread data storage..PP\fINote that due to compiler limitations, QThreadStorage can only store pointers.\fR.PPThe 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 \fInew\fR) and deletes it when the thread exits (either normally or via termination)..PPThe hasLocalData() function allows the programmer to determine if data has previously been set using the setLocalData() function. This is useful for lazy initializiation..PPFor example, the following code uses QThreadStorage to store a single cache for each thread that calls the \fIcacheObject()\fR and \fIremoveFromCache()\fR functions. The cache is automatically deleted when the calling thread exits (either normally or via termination)..PP.nf.br    QThreadStorage<QCache<SomeClass> *> caches;.br.br    void cacheObject( const QString &key, SomeClass *object ).br    {.br        if ( ! caches.hasLocalData() ).br            caches.setLocalData( new QCache<SomeClass> );.br.br        caches.localData()->insert( key, object );.br    }.br.br    void removeFromCache( const QString &key ).br    {.br        if ( ! caches.hasLocalData() ).br            return; // nothing to do.br.br        caches.localData()->remove( key );.br    }.br.fi.SH "Caveats".IP.TPAs noted above, QThreadStorage can only store pointers due to compiler limitations. Support for value-based objects will be added when the majority of compilers are able to support partial template specialization..IP.TPThe destructor does \fInot\fR delete per-thread data. QThreadStorage only deletes per-thread data when the thread exits or when setLocalData() is called multiple times..IP.TPQThreadStorage can only be used with threads started with QThread. It \fIcannot\fR be used with threads started with platform-specific APIs..IP.TPAs a corollary to the above, platform-specific APIs cannot be used to exit or terminate a QThread using QThreadStorage. Doing so will cause all per-thread data to be leaked. See QThread::exit() and QThread::terminate()..IP.TPQThreadStorage \fIcan\fR be used to store data for the \fImain()\fR thread \fIafter\fR QApplication has been constructed. QThreadStorage deletes all data set for the \fImain()\fR thread when QApplication is destroyed, regardless of whether or not the \fImain()\fR thread has actually finished..IP.TPThe implementation of QThreadStorage limits the total number of QThreadStorage objects to 256. An unlimited number of threads can store per-thread data in each QThreadStorage object..IP.PPSee also Environment Classes and Threading..SH MEMBER FUNCTION DOCUMENTATION.SH "QThreadStorage::QThreadStorage ()"Constructs a new per-thread data storage object..SH "QThreadStorage::~QThreadStorage ()"Destroys the per-thread data storage object..PPNote: The per-thread data stored is \fInot\fR deleted. Any data left in QThreadStorage is leaked. Make sure that all threads using QThreadStorage have exited before deleting the QThreadStorage..PPSee also hasLocalData()..SH "bool QThreadStorage::hasLocalData () const"Returns TRUE if the calling thread has non-zero data available; otherwise returns FALSE..PPSee also localData()..SH "T & QThreadStorage::localData ()"Returns a reference to the data that was set by the calling thread..PPNote: QThreadStorage can only store pointers. This function returns a \fIreference\fR to the pointer that was set by the calling thread. The value of this reference is 0 if no data was set by the calling thread,.PPSee also hasLocalData()..SH "T QThreadStorage::localData () const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns a copy of the data that was set by the calling thread..PPNote: QThreadStorage can only store pointers. This function returns a pointer to the data that was set by the calling thread. If no data was set by the calling thread, this function returns 0..PPSee also hasLocalData()..SH "void QThreadStorage::setLocalData ( T data )"Sets the local data for the calling thread to \fIdata\fR. It can be accessed later using the localData() functions..PPIf \fIdata\fR is 0, this function deletes the previous data (if any) and returns immediately..PPIf \fIdata\fR is non-zero, QThreadStorage takes ownership of the \fIdata\fR and deletes it automatically either when the thread exits (either normally or via termination) or when setLocalData() is called again..PPNote: QThreadStorage can only store pointers. The \fIdata\fR argument must be either a pointer to an object created on the heap (i.e. using \fInew\fR) or 0. You should not delete \fIdata\fR yourself; QThreadStorage takes ownership and will delete the \fIdata\fR itself..PPSee also localData() and hasLocalData()..SH "SEE ALSO".BR http://doc.trolltech.com/qthreadstorage.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com.  See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qthreadstorage.3qt) and the Qtversion (3.3.4).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -