📄 qvaluevector.3qt
字号:
'\" t.TH QValueVector 3qt "11 October 2001" "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 NAMEQValueVector \- Value-based template class that provides a dynamic array.PP\fC#include <qvaluevector.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "typedef T \fBvalue_type\fR".br.ti -1c.BI "typedef value_type * \fBpointer\fR".br.ti -1c.BI "typedef const value_type * \fBconst_pointer\fR".br.ti -1c.BI "typedef value_type * \fBiterator\fR".br.ti -1c.BI "typedef const value_type * \fBconst_iterator\fR".br.ti -1c.BI "typedef value_type & \fBreference\fR".br.ti -1c.BI "typedef const value_type & \fBconst_reference\fR".br.ti -1c.BI "typedef size_t \fBsize_type\fR".br.ti -1c.BI "typedef ptrdiff_t \fBdifference_type\fR".br.ti -1c.BI "\fBQValueVector\fR ()".br.ti -1c.BI "\fBQValueVector\fR ( const QValueVector<T> & v )".br.ti -1c.BI "\fBQValueVector\fR ( size_type n, const T & val = T ( ) )".br.ti -1c.BI "\fBQValueVector\fR ( std::vector<T> & v )".br.ti -1c.BI "\fB~QValueVector\fR ()".br.ti -1c.BI "QValueVector<T> & \fBoperator=\fR ( const QValueVector<T> & v )".br.ti -1c.BI "QValueVector<T> & \fBoperator=\fR ( const std::vector<T> & v )".br.ti -1c.BI "size_type \fBsize\fR () const".br.ti -1c.BI "bool \fBempty\fR () const".br.ti -1c.BI "size_type \fBcapacity\fR () const".br.ti -1c.BI "iterator \fBbegin\fR ()".br.ti -1c.BI "const_iterator \fBbegin\fR () const".br.ti -1c.BI "iterator \fBend\fR ()".br.ti -1c.BI "const_iterator \fBend\fR () const".br.ti -1c.BI "reference \fBat\fR ( size_type i, bool * ok = 0 )".br.ti -1c.BI "const_reference \fBat\fR ( size_type i, bool * ok = 0 ) const".br.ti -1c.BI "reference \fBoperator[]\fR ( size_type i )".br.ti -1c.BI "const_reference \fBoperator[]\fR ( size_type i ) const".br.ti -1c.BI "reference \fBfront\fR ()".br.ti -1c.BI "const_reference \fBfront\fR () const".br.ti -1c.BI "reference \fBback\fR ()".br.ti -1c.BI "const_reference \fBback\fR () const".br.ti -1c.BI "void \fBpush_back\fR ( const T & x )".br.ti -1c.BI "void \fBpop_back\fR ()".br.ti -1c.BI "iterator \fBinsert\fR ( iterator pos, const T & x )".br.ti -1c.BI "iterator \fBinsert\fR ( iterator pos, size_type n, const T & x )".br.ti -1c.BI "void \fBreserve\fR ( size_type n )".br.ti -1c.BI "void \fBresize\fR ( size_type n, const T & val = T ( ) )".br.ti -1c.BI "void \fBclear\fR ()".br.ti -1c.BI "iterator \fBerase\fR ( iterator pos )".br.ti -1c.BI "iterator \fBerase\fR ( iterator first, iterator last )".br.ti -1c.BI "bool \fBoperator==\fR ( const QValueVector<T> & x )".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "void \fBdetach\fR ()".br.in -1c.SH DESCRIPTIONThe QValueVector class is a value-based template class that provides a dynamic array..PPQValueVector is a Qt implementation of an STL-like vector container. It can be used in your application if the standard \fCvector\fR is not available. QValueVector is part of the Qt Template Library..PPQValueVector<T> defines a template instance to create a vector of values that all have the class T. Please note that QValueVector does not store pointers to the members of the vector; it holds a copy of every member. QValueVector is said to be value based; in contrast, QPtrList and QDict are pointer based..PPQValueVector contains and manages a collection of objects of type T and provides random access iterators that allow the contained objects to be addressed. QValueVector owns the contained elements. For more relaxed ownership semantics, see QPtrCollection and friends which are pointer-based containers..PPQValueVector provides good performance if you append or remove elements from the end of the vector. If you insert or remove elements from anywhere but the end, performance is very bad. The reason for this is that elements will need to be copied into new positions..PPSome classes cannot be used within a QValueVector - for example, all classes derived from QObject and thus all classes that implement widgets. Only values can be used in a QValueVector. To qualify as a value the class must provide:.TPA copy constructor.TPAn assignment operator.TPA default constructor, i.e., a constructor that does not take any arguments..PPNote that C++ defaults to field-by-field assignment operators and copy constructors if no explicit version is supplied. In many cases this is sufficient..PPQValueVector uses an STL-like syntax to manipulate and address the objects it contains. See this document for more information..PPExample:.PP.nf.br #include <qvaluevector.h>.br #include <qstring.h>.br #include <stdio.h>.br.br class Employee.br {.br public:.br Employee(): s(0) {}.br Employee( const QString& name, int salary ).br : n(name), s(salary).br {}.br.br QString name() const { return n; }.br int salary() const { return s; }.br void setSalary( int salary ) { s = salary; }.br private:.br QString n;.br int s;.br };.br.br int main().br {.br typedef QValueVector<Employee> EmployeeVector;.br EmployeeVector vec( 4 ); // vector of 4 Employees.br.br vec[0] = Employee("Bill", 50000);.br vec[1] = Employee("Steve",80000);.br vec[2] = Employee("Ron", 60000);.br.br Employee joe( "Joe", 50000 );.br vec.push_back( joe );.br joe.setSalary( 4000 );.br.br.br EmployeeVector::iterator it;.br for( it = vec.begin(); it != vec.end(); ++it ).br printf( "%s earns %d\\n", (*it).name().latin1(), (*it).salary() );.br.br return 0;.br }.br.fi.PPProgram output:.PP.nf.br Bill earns 50000.br Steve earns 80000.br Ron earns 60000.br Joe earns 50000.br.fi.PPAs you can see, the latest changes to Joe's salary did not affect the value in the vector because the vector created a copy of Joe's entry..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -