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

📄 qvaluelist.3qt

📁 Linux 下的图形编程环境。
💻 3QT
📖 第 1 页 / 共 2 页
字号:
            printf( "%s earns %d\\n", (*it).name().latin1(), (*it).salary().latin1() );.br    }.fi.PPProgram output:.PP.nf.br        Bill earns 50000.br        Steve earns 80000.br        Ron earns 60000.br        Joe earns 50000.fi.PPAs you can see, the latest changes to Joes salary did not affect the value in the list because the list created a copy of Joes entry..PPThere are three ways of finding items in the list. The first one is by using the at() function. It returns an iterator. The advantages of getting an iterator is that you can now move forward or backward from this position by incrementing/decrementing the iterator. To get the amount of items in the list call count(). Valid indices are 0..count()..PPThe second way of accessing a list is with operator[]. That means you can address it like an array. The return value is a reference to the value stored in the list. There exist two versions of this operator. The first one is const and returns a const reference to the value. The second on is non const and returns a non const reference to the value. It is up to your compiler to choose the correct one..PPThe third method is to use the functions begin() and end(). With a simple for loop as shown in the example you can iterate over the complete list. It is save to have multiple iterators at the same time. If some member of the list is removed then only iterators pointing to the removed member become invalid. Inserting in the list does not invalidate any iterator. For convenience the function last() returns an iterator for the last and first() for the first element in the list..PPIn addition you can search items in the list with the find() function. It exists in a const and a non const version. It starts searching from the beginning of the list, but another flavor of the find() function allows you to specify where searching should start. If you just want to know wether a certain item is at least once in the list, then you can use the contains() function..PPSince QValueList is value based there is no need to care about deleting elements in the list. The list holds its own copies and will free them if the corresponding member or the list itself is deleted. You can force the list to free all of its item with clear()..PPQValueList is implicitly shared. That means you can just make copies of the list in time O(1). If multiple QValueList instances share the same data and one is doing a modification of the lists data then this modifying instance makes a copy and modifies its private copy. So it does not affect the other instances. From a developers point of view you can think that a QValueList and a copy of this list have nothing to do with each other. Developers may only notice that copying is very fast. People known to a CPUs MMU architecture will know this pattern as "copy on write"..PPThere exist three functions to insert items in the list. append() inserts an item at the end, prepend() inserts at the beginning and insert() inserts in front of the position given by an iterator..PPItems can be removed from the list in two ways. The first is to pass an iterator to the remove(). The other possibility is to pass a value to remove() which will delete all members which match this value..PPLists can be sorted with the algorithms provided by the Qt Template Library, for example with qHeapSort():.PPExample:.PP.nf.br          QValueList l;.br          l.append( 5 );.br          l.append( 8 );.br          l.append( 3 );.br          l.append( 4 );.br          qHeapSort( l );.fi.PPSee also QValueListIterator..SH MEMBER FUNCTION DOCUMENTATION.SH "QValueList::QValueList ()"Constructs an empty list..SH "QValueList::QValueList ( const QValueList<T> & l )"Constructs a copy of \fIl.\fR.PPThis operation costs O(1) time since QValueList is implicit shared. The first instance applying modifications to a shared list will create a copy which takes in turn O(n) time. However returning a QValueList from a function is very fast..SH "QValueList::~QValueList ()"Destroys the list. References to the values in the list and all iterators of this list become invalidated. Since QValueList is highly tuned for performance you wont see warnings if you use invalid iterators, because it is impossible for an iterator to check wether it is valid or not..SH "Iterator QValueList::append ( const T & x )"Inserts the value \fIx\fR at the end of the list..PPReturns an iterator pointing at the inserted item..PPSee also insert() and prepend()..SH "ConstIterator QValueList::at ( uint i ) const"Returns an iterator pointing to the item at position \fIi\fR in the list, or end() if the index is out of range..SH "Iterator QValueList::at ( uint i )"Returns an iterator pointing to the item at position \fIi\fR in the list, or end() if the index is out of range..SH "ConstIterator QValueList::begin () const"Returns an iterator pointing to the first element in the list. This iterator equals end() if the list is empty;.PPSee also first() and end()..SH "Iterator QValueList::begin ()"Returns an iterator pointing to the first element in the list. This iterator equals end() if the list is empty;.PPSee also first() and end()..SH "void QValueList::clear ()"Removes all items from the list..PPSee also remove()..SH "uint QValueList::contains ( const T & x ) const"Counts and returns the number of occurrences of the value \fIx\fR in the list..SH "uint QValueList::count () const"Returns the number of items in the list..PPSee also isEmpty()..SH "void QValueList::detach () \fC[protected]\fR"If the list does not share its data with another QValueList instance, then nothing happens, otherwise the function creates a new copy of this data and detaches from the shared one. This function is called whenever the list is modified. The implicit sharing mechanism is implemented this way..SH "ConstIterator QValueList::end () const"Returns an iterator pointing behind the last element in the list. This iterator equals begin() if the list is empty..PPSee also last() and begin()..SH "Iterator QValueList::end ()"Returns an iterator pointing behind the last element in the list. This iterator equals begin() if the list is empty..PPSee also last() and begin()..SH "ConstIterator QValueList::find ( ConstIterator it, const T & x ) const"Finds the first occurrence of \fIx\fR in the list starting at the position given by \fIit.\fR.PPReturns end() if no item did match..SH "ConstIterator QValueList::find ( const T & x ) const"Finds the first occurrence of \fIx\fR in the list..PPReturns end() if no item did match..SH "Iterator QValueList::find ( Iterator it, const T & x )"Finds the first occurrence of \fIx\fR in the list starting at the position given by \fIit.\fR.PPReturns end() if no item did match..SH "Iterator QValueList::find ( const T & x )"Finds the first occurrence of \fIx\fR in the list..PPReturns end() if no item did match..SH "int QValueList::findIndex ( const T & x ) const"Returns the first index of the value \fIx\fR in the list or -1 if no such value can be found in the list..SH "T& QValueList::first ()"Returns a reference to the first item in the list or the item referenced by end() if no such items exists. Please note that you may not change the value the end() Iterator is pointing to..PPSee also begin() and last()..SH "const T& QValueList::first () const"Returns a reference to the first item in the list or the item referenced by end() if no such items exists..PPSee also begin() and last()..SH "ConstIterator QValueList::fromLast () const"Returns an iterator pointing to the last element in the list or end() if no such item exists..PPSee also last()..SH "Iterator QValueList::fromLast ()"Returns an iterator pointing to the last element in the list or end() if no such item exists..PPSee also last()..SH "Iterator QValueList::insert ( Iterator it, const T & x )"Inserts the value \fIx\fR in front of the iterator \fIit.\fR.PPReturns an iterator pointing at the inserted item..PPSee also append() and prepend()..SH "bool QValueList::isEmpty () const"Returns TRUE if the list is empty, i.e. count() == 0. Returns FALSE otherwise..PPSee also count()..SH "T& QValueList::last ()"Returns a reference to the last item in the list or the item referenced by end() if no such item exists. Please note that you may not change the value the end() Iterator is pointing to..PPSee also end(), first() and fromLast()..SH "const T& QValueList::last () const"Returns a reference to the last item in the list or the item referenced by end() if no such item exists..PPSee also end(), first() and fromLast()..SH "bool QValueList::operator!= ( const QValueList<T> & l ) const"Compares both lists..PPReturns TRUE if both list are unequal..SH "QValueList<T> QValueList::operator+ ( const QValueList<T> & l ) const"Creates a new list and fills it with the elements of this list. Then the elements of \fIl\fR are appended..PPReturns the new list..SH "QValueList<T>& QValueList::operator+= ( const QValueList<T> & l )"Adds \fIlist\fR to this list..PPReturns a reference to this list..SH "QValueList<T>& QValueList::operator+= ( const T & x )"Adds the value \fIx\fR to the end of the list..PPReturns a reference to the list..SH "QValueList<T>& QValueList::operator<< ( const T & x )"Adds the value \fIx\fR to the end of the list..PPReturns a reference to the list..SH "QValueList<T>& QValueList::operator= ( const QValueList<T> & l )"Assigns \fIl\fR to this list and returns a reference to this list..PPAll iterators of the current list become invalidated by this operation. The cost of such an assignment is O(1) since QValueList is implicitly shared..SH "bool QValueList::operator== ( const QValueList<T> & l ) const"Compares both lists..PPReturns TRUE if both list are equal..SH "T& QValueList::operator[] ( uint i )"Returns a reference to the item with index \fIi\fR in the list. It is up to you to check wether this item really exists. You can do that easily with the count() function. However this operator does not check wether \fIi\fR is in range and will deliver undefined results if it does not exist. In contrast to the const operator[] you may manipulate the value returned by this operator..SH "const T& QValueList::operator[] ( uint i ) const"Returns a const reference to the item with index \fIi\fR in the list. It is up to you to check wether this item really exists. You can do that easily with the count() function. However this operator does not check wether \fIi\fR is in range and will deliver undefined results if it does not exist..SH "Iterator QValueList::prepend ( const T & x )"Inserts the value \fIx\fR at the beginning of the list..PPReturns an iterator pointing at the inserted item..PPSee also insert() and append()..SH "Iterator QValueList::remove ( Iterator it )"Removes the item at position \fIit\fR in the list..PPReturns an iterator pointing to the item following the removed on or end() if the last item was deleted..PPSee also clear()..SH "void QValueList::remove ( const T & x )"Removes all items which have the value \fIx.\fR.PPSee also clear()..SH RELATED FUNCTION DOCUMENTATION.SH "QDataStream& operator<< (QDataStream & s, const QValueList<T> & l)"Writes a list to the stream. The type \fIT\fR stored in the list must implement the streaming operator, too..SH "QDataStream& operator>> (QDataStream & s, QValueList<T> & l)"Reads a list from the stream. The type \fIT\fR stored in the list must implementthe streaming operator, too..SH "SEE ALSO".BR http://doc.trolltech.com/qvaluelist.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 make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qvaluelist.3qt) and the Qtversion (2.3.0).

⌨️ 快捷键说明

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