📄 qlist.3qt
字号:
'\" t.TH QList 3qt "17 July 2003" "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 NAMEQList \- Template class that provides doubly linked lists.br.PP\fC#include <qlist.h>\fR.PPInherits QGList..PPInherited by QStrList..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQList\fR () ".br.ti -1c.BI "\fBQList\fR ( const QList<type> & list ) ".br.ti -1c.BI "\fB~QList\fR () ".br.ti -1c.BI "QList<type>& \fBoperator=\fR ( const QList<type> & list ) ".br.ti -1c.BI "bool \fBoperator==\fR ( const QList<type> & list ) const".br.ti -1c.BI "virtual uint \fBcount\fR () const".br.ti -1c.BI "bool \fBisEmpty\fR () const".br.ti -1c.BI "bool \fBinsert\fR ( uint " "index" ", const type * item ) ".br.ti -1c.BI "void \fBinSort\fR ( const type * item ) ".br.ti -1c.BI "void \fBprepend\fR ( const type * item ) ".br.ti -1c.BI "void \fBappend\fR ( const type * item ) ".br.ti -1c.BI "bool \fBremove\fR ( uint index ) ".br.ti -1c.BI "bool \fBremove\fR () ".br.ti -1c.BI "bool \fBremove\fR ( const type * item ) ".br.ti -1c.BI "bool \fBremoveRef\fR ( const type * item ) ".br.ti -1c.BI "void \fBremoveNode\fR ( QLNode * node ) ".br.ti -1c.BI "bool \fBremoveFirst\fR () ".br.ti -1c.BI "bool \fBremoveLast\fR () ".br.ti -1c.BI "type* \fBtake\fR ( uint index ) ".br.ti -1c.BI "type* \fBtake\fR () ".br.ti -1c.BI "type* \fBtakeNode\fR ( QLNode * node ) ".br.ti -1c.BI "virtual void \fBclear\fR () ".br.ti -1c.BI "void \fBsort\fR () ".br.ti -1c.BI "int \fBfind\fR ( const type * item ) ".br.ti -1c.BI "int \fBfindNext\fR ( const type * item ) ".br.ti -1c.BI "int \fBfindRef\fR ( const type * item ) ".br.ti -1c.BI "int \fBfindNextRef\fR ( const type * item ) ".br.ti -1c.BI "uint \fBcontains\fR ( const type * item ) const".br.ti -1c.BI "uint \fBcontainsRef\fR ( const type * item ) const".br.ti -1c.BI "type* \fBat\fR ( uint index ) ".br.ti -1c.BI "int \fBat\fR () const".br.ti -1c.BI "type* \fBcurrent\fR () const".br.ti -1c.BI "QLNode* \fBcurrentNode\fR () const".br.ti -1c.BI "type* \fBgetFirst\fR () const".br.ti -1c.BI "type* \fBgetLast\fR () const".br.ti -1c.BI "type* \fBfirst\fR () ".br.ti -1c.BI "type* \fBlast\fR () ".br.ti -1c.BI "type* \fBnext\fR () ".br.ti -1c.BI "type* \fBprev\fR () ".br.ti -1c.BI "void \fBtoVector\fR ( QGVector * vec ) const".br.in -1c.SH DESCRIPTIONThe QList class is a template class that provides doubly linked lists..PPIn Qt 2.0 QList is only implemented as a template class. Define a template instance QList<X> to create a list that operates on pointers to X, or X*..PPExample:.PP.nf.br #include <qlist.h>.br #include <qstring.h>.br #include <stdio.h>.br.br class Employee.br {.br public:.br Employee( const QString& name, int salary ) { n=name; s=salary; }.br QString name() const { return n; }.br int salary() const { return s; }.br private:.br QString n;.br int s;.br };.br.br void main().br {.br QList<Employee> list; // list of pointers to Employee.br list.setAutoDelete( TRUE ); // delete items when they are removed.br.br list.append( new Employee("Bill", 50000) );.br list.append( new Employee("Steve",80000) );.br list.append( new Employee("Ron", 60000) );.br.br Employee *emp;.br for ( emp=list.first(); emp != 0; emp=list.next() ).br printf( "%s earns %d\\n", emp->name().latin1(), emp->salary() );.br }.fi.PPProgram output:.PP.nf.br Bill earns 50000.br Steve earns 80000.br Ron earns 60000.fi.PPThe list class is indexable and has a current index and a current item. The first item corresponds to index 0. The current index is -1 if the current item is null..PPQList has several member functions for traversing the list, but using a QListIterator can be more practical. Multiple list iterators may traverse the same list, independent of each other and independent of the current list item..PPIn the example above, we make the call setAutoDelete(TRUE). Enabling auto-deletion tells the list to delete items that are removed from the list. The default is to not delete items when they are removed, but that would cause a memory leak in our example since we have no other references to the list items..PPList items are stored as \fCvoid*\fR in an internal QLNode, which also holds pointers to the next and previous list items. The functions currentNode(), removeNode() and takeNode() operate directly on the QLNode, but they should be used with care..PPWhen inserting an item into a list, only the pointer is copied, not the item itself. This is called a shallow copy. It is possible to make the list copy all of the item's data (known as a deep copy) when an item is inserted. insert(), inSort() and append() call the virtual function QCollection::newItem() for the item to be inserted. Inherit a list and reimplement it if you want deep copies..PPWhen removing an item from a list, the virtual function QCollection::deleteItem() is called. QList's default implementation is to delete the item if auto-deletion is enabled..PPThe virtual function QGList::compareItems() can be reimplemented to compare two list items. This function is called from all list functions that need to compare list items, for instance remove(const type*). If you only want to deal with pointers, there are functions that compare pointers instead, for instance removeRef(const type*). These functions are somewhat faster than those that call compareItems()..PPThe QStrList class in qstrlist.h is a list of \fCchar*.\fR QStrList is a good example of a list that reimplements newItem(), deleteItem() and compareItems().PPSee also QListIterator and Collection Classes.PPExamples:.(lgrapher/grapher.cpp.)l.SH MEMBER FUNCTION DOCUMENTATION.SH "QList::QList ()"Constructs an empty list..SH "QList::QList ( const QList<type> & list )"Constructs a copy of \fIlist.\fR.PPEach item in \fIlist\fR is appended to this list. Only the pointers are copied (shallow copy)..SH "QList::~QList ()"Removes all items from the list and destroys the list..PPAll list iterators that access this list will be reset..PPSee also setAutoDelete()..SH "void QList::append ( const type * item )"Inserts the \fIitem\fR at the end of the list..PPThe inserted item becomes the current list item. This is equivalent to \fCinsert(count(),item).\fR.PPThe \fIitem\fR must not be a null pointer..PPSee also insert(), current() and prepend()..PPExamples:.(lgrapher/grapher.cpp.)l.SH "int QList::at () const"Returns the index of the current list item. The returned value is -1 if the current item is null..PPSee also current()..SH "type * QList::at ( uint index )"Returns a pointer to the item at position \fIindex\fR in the list, or null if the index is out of range..PPSets the current list item to this item if \fIindex\fR is valid. The valid range is \fC0 .. (count() - 1)\fR inclusive..PPThis function is very efficient. It starts scanning from the first item, last item or current item, whichever is closest to \fIindex.\fR.PPSee also current()..SH "void QList::clear () \fC[virtual]\fR"Removes all items from the list..PPThe removed items are deleted if auto-deletion is enabled..PPAll list iterators that access this list will be reset..PPSee also remove(), take() and setAutoDelete()..PPReimplemented from QCollection..SH "uint QList::contains ( const type * item ) const"Counts and returns the number of occurrences of \fIitem\fR in the list..PPThe compareItems() function is called when looking for the \fIitem\fR in the list. If compareItems() is not reimplemented, it is more efficient to call containsRef()..PPDoes not affect the current list item..PPSee also containsRef() and compareItems()..SH "uint QList::containsRef ( const type * item ) const"Counts and returns the number of occurrences of \fIitem\fR in the list..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -