Qt 4.8
Public Types | Public Functions | Static Public Functions | Private Types | Private Functions | Properties | Friends | Related Functions | List of all members
QVector< T > Class Template Reference

The QVector class is a template class that provides a dynamic array. More...

#include <qdatastream.h>

Inheritance diagram for QVector< T >:
QStack< T > QStack< AccelTree::PreNumber > QStack< CurrentNode > QStack< Iterator *> QStack< OrderBy::Stability > QStack< ProcessMode > QStack< QAbstractFileEngineIterator *> QStack< QAbstractItemModelPrivate::Change > QStack< QEventLoop *> QStack< QFileSystemIterator *> QStack< QHash > QStack< QMap< QString, QString > > QStack< QPair > QStack< QPair< Event, QXmlNodeModelIndex::Iterator::Ptr > > QStack< QPair< QXmlName, bool > > QStack< QPatternist::XsdStateMachine< QExplicitlySharedDataPointer > > QStack< QSettingsGroup > QStack< QStringList > QStack< QSvgNode *> QStack< QSvgText::WhitespaceMode > QStack< QTextBrowserPrivate::HistoryEntry > QStack< QTextList *> QStack< QVector< QPersistentModelIndexData *> > QStack< QVector< QXmlName > > QStack< QXmlSimpleReaderPrivate::ParseState > QStack< QXmlSimpleReaderPrivate::XmlRef > QStack< State > QStack< Token > QStack< VariableDeclaration::Ptr >

Public Types

typedef const T * const_iterator
 The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack. More...
 
typedef const value_typeconst_pointer
 Typedef for const T *. More...
 
typedef const value_typeconst_reference
 Typedef for T &. More...
 
typedef const_iterator ConstIterator
 Qt-style synonym for QVector::const_iterator. More...
 
typedef qptrdiff difference_type
 Typedef for ptrdiff_t. More...
 
typedef T * iterator
 The QVector::iterator typedef provides an STL-style non-const iterator for QVector and QStack. More...
 
typedef iterator Iterator
 Qt-style synonym for QVector::iterator. More...
 
typedef value_typepointer
 Typedef for T *. More...
 
typedef value_typereference
 Typedef for T &. More...
 
typedef int size_type
 Typedef for int. More...
 
typedef T value_type
 Typedef for T. More...
 

Public Functions

void append (const T &t)
 Inserts value at the end of the vector. More...
 
const T & at (int i) const
 Returns the item at index position i in the vector. More...
 
reference back ()
 This function is provided for STL compatibility. More...
 
const_reference back () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
iterator begin ()
 Returns an STL-style iterator pointing to the first item in the vector. More...
 
const_iterator begin () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int capacity () const
 Returns the maximum number of items that can be stored in the vector without forcing a reallocation. More...
 
void clear ()
 Removes all the elements from the vector and releases the memory used by the vector. More...
 
const_iterator constBegin () const
 Returns a const STL-style iterator pointing to the first item in the vector. More...
 
const T * constData () const
 Returns a const pointer to the data stored in the vector. More...
 
const_iterator constEnd () const
 Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector. More...
 
bool contains (const T &t) const
 Returns true if the vector contains an occurrence of value; otherwise returns false. More...
 
int count (const T &t) const
 Returns the number of occurrences of value in the vector. More...
 
int count () const
 Same as size(). More...
 
T * data ()
 Returns a pointer to the data stored in the vector. More...
 
const T * data () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void detach ()
 
bool empty () const
 This function is provided for STL compatibility. More...
 
iterator end ()
 Returns an STL-style iterator pointing to the imaginary item after the last item in the vector. More...
 
const_iterator end () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool endsWith (const T &t) const
 Returns true if this vector is not empty and its last item is equal to value; otherwise returns false. More...
 
iterator erase (iterator begin, iterator end)
 Removes all the items from begin up to (but not including) end. More...
 
iterator erase (iterator pos)
 Removes the item pointed to by the iterator pos from the vector, and returns an iterator to the next item in the vector (which may be end()). More...
 
QVector< T > & fill (const T &t, int size=-1)
 Assigns value to all items in the vector. More...
 
T & first ()
 Returns a reference to the first item in the vector. More...
 
const T & first () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
T & front ()
 This function is provided for STL compatibility. More...
 
const_reference front () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int indexOf (const T &t, int from=0) const
 Returns the index position of the first occurrence of value in the vector, searching forward from index position from. More...
 
void insert (int i, const T &t)
 Inserts value at index position i in the vector. More...
 
void insert (int i, int n, const T &t)
 Inserts count copies of value at index position i in the vector. More...
 
iterator insert (iterator before, int n, const T &x)
 Inserts count copies of value in front of the item pointed to by the iterator before. More...
 
iterator insert (iterator before, const T &x)
 Inserts value in front of the item pointed to by the iterator before. More...
 
bool isDetached () const
 
bool isEmpty () const
 Returns true if the vector has size 0; otherwise returns false. More...
 
bool isSharedWith (const QVector< T > &other) const
 
T & last ()
 Returns a reference to the last item in the vector. More...
 
const T & last () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int lastIndexOf (const T &t, int from=-1) const
 Returns the index position of the last occurrence of the value value in the vector, searching backward from index position from. More...
 
QVector< T > mid (int pos, int length=-1) const
 Returns a vector whose elements are copied from this vector, starting at position pos. More...
 
bool operator!= (const QVector< T > &v) const
 Returns true if other is not equal to this vector; otherwise returns false. More...
 
QVector< T > operator+ (const QVector< T > &l) const
 Returns a vector that contains all the items in this vector followed by all the items in the other vector. More...
 
QVector< T > & operator+= (const QVector< T > &l)
 Appends the items of the other vector to this vector and returns a reference to this vector. More...
 
QVector< T > & operator+= (const T &t)
 Appends value to the vector. More...
 
QVector< T > & operator<< (const QVector< T > &l)
 Appends other to the vector and returns a reference to the vector. More...
 
QVector< T > & operator<< (const T &t)
 Appends value to the vector and returns a reference to this vector. More...
 
QVector< T > & operator= (const QVector< T > &v)
 Assigns other to this vector and returns a reference to this vector. More...
 
bool operator== (const QVector< T > &v) const
 Returns true if other is equal to this vector; otherwise returns false. More...
 
T & operator[] (int i)
 Returns the item at index position i as a modifiable reference. More...
 
const T & operator[] (int i) const
 Same as at(i). More...
 
void pop_back ()
 This function is provided for STL compatibility. More...
 
void pop_front ()
 This function is provided for STL compatibility. More...
 
void prepend (const T &t)
 Inserts value at the beginning of the vector. More...
 
void push_back (const T &t)
 This function is provided for STL compatibility. More...
 
void push_front (const T &t)
 This function is provided for STL compatibility. More...
 
 QVector ()
 Constructs an empty vector. More...
 
 QVector (int size)
 Constructs a vector with an initial size of size elements. More...
 
 QVector (int size, const T &t)
 Constructs a vector with an initial size of size elements. More...
 
 QVector (const QVector< T > &v)
 Constructs a copy of other. More...
 
void remove (int i)
 Removes the element at index position i. More...
 
void remove (int i, int n)
 Removes count elements from the middle of the vector, starting at index position i. More...
 
void replace (int i, const T &t)
 Replaces the item at index position i with value. More...
 
void reserve (int size)
 Attempts to allocate memory for at least size elements. More...
 
void resize (int size)
 Sets the size of the vector to size. More...
 
void setSharable (bool sharable)
 
int size () const
 Returns the number of items in the vector. More...
 
void squeeze ()
 Releases any memory not required to store the items. More...
 
bool startsWith (const T &t) const
 Returns true if this vector is not empty and its first item is equal to value; otherwise returns false. More...
 
void swap (QVector< T > &other)
 Swaps vector other with this vector. More...
 
QList< T > toList () const
 Returns a QList object with the data contained in this QVector. More...
 
std::vector< T > toStdVector () const
 Returns a std::vector object with the data contained in this QVector. More...
 
value (int i) const
 Returns the value at index position i in the vector. More...
 
value (int i, const T &defaultValue) const
 If the index i is out of bounds, the function returns defaultValue. More...
 
 ~QVector ()
 Destroys the vector. More...
 

Static Public Functions

static QVector< T > fromList (const QList< T > &list)
 Returns a QVector object with the data contained in list. More...
 
static QVector< T > fromStdVector (const std::vector< T > &vector)
 Returns a QVector object with the data contained in vector. More...
 

Private Types

typedef QVectorTypedData< T > Data
 

Private Functions

int alignOfTypedData () const
 
void detach_helper ()
 
void free (Data *d)
 
QVectorDatamalloc (int alloc)
 
void realloc (int size, int alloc)
 
int sizeOfTypedData ()
 

Properties

union {
   QVectorData *   d
 
   Data *   p
 
}; 
 

Friends

class QRegion
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QVector< T > &vector)
 Writes the vector vector to stream out. More...
 
QDataStreamoperator>> (QDataStream &in, QVector< T > &vector)
 Reads a vector from stream in into vector. More...
 

Detailed Description

template<typename T>
class QVector< T >

The QVector class is a template class that provides a dynamic array.

Note
This class or function is reentrant.

QVector<T> is one of Qt's generic container classes. It stores its items in adjacent memory locations and provides fast index-based access.

QList<T>, QLinkedList<T>, and QVarLengthArray<T> provide similar functionality. Here's an overview:

Here's an example of a QVector that stores integers and a QVector that stores QString values:

QVector<int> integerVector;
QVector<QString> stringVector;

QVector stores a vector (or array) of items. Typically, vectors are created with an initial size. For example, the following code constructs a QVector with 200 elements:

QVector<QString> vector(200);

The elements are automatically initialized with a default-constructed value. If you want to initialize the vector with a different value, pass that value as the second argument to the constructor:

QVector<QString> vector(200, "Pass");

You can also call fill() at any time to fill the vector with a value.

QVector uses 0-based indexes, just like C++ arrays. To access the item at a particular index position, you can use operator[](). On non-const vectors, operator[]() returns a reference to the item that can be used on the left side of an assignment:

if (vector[0] == "Liz")
vector[0] = "Elizabeth";

For read-only access, an alternative syntax is to use at():

for (int i = 0; i < vector.size(); ++i) {
if (vector.at(i) == "Alfonso")
cout << "Found Alfonso at position " << i << endl;
}

at() can be faster than operator[](), because it never causes a deep copy to occur.

Another way to access the data stored in a QVector is to call data(). The function returns a pointer to the first item in the vector. You can use the pointer to directly access and modify the elements stored in the vector. The pointer is also useful if you need to pass a QVector to a function that accepts a plain C++ array.

If you want to find all occurrences of a particular value in a vector, use indexOf() or lastIndexOf(). The former searches forward starting from a given index position, the latter searches backward. Both return the index of the matching item if they found one; otherwise, they return -1. For example:

int i = vector.indexOf("Harumi");
if (i != -1)
cout << "First occurrence of Harumi is at position " << i << endl;

If you simply want to check whether a vector contains a particular value, use contains(). If you want to find out how many times a particular value occurs in the vector, use count().

QVector provides these basic functions to add, move, and remove items: insert(), replace(), remove(), prepend(), append(). With the exception of append() and replace(), these functions can be slow (linear time) for large vectors, because they require moving many items in the vector by one position in memory. If you want a container class that provides fast insertion/removal in the middle, use QList or QLinkedList instead.

Unlike plain C++ arrays, QVectors can be resized at any time by calling resize(). If the new size is larger than the old size, QVector might need to reallocate the whole vector. QVector tries to reduce the number of reallocations by preallocating up to twice as much memory as the actual data needs.

If you know in advance approximately how many items the QVector will contain, you can call reserve(), asking QVector to preallocate a certain amount of memory. You can also call capacity() to find out how much memory QVector actually allocated.

Note that using non-const operators and functions can cause QVector to do a deep copy of the data. This is due to implicit sharing.

QVector's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; for example, indexOf() and lastIndexOf() expect the value type to support operator==(). These requirements are documented on a per-function basis.

Like the other container classes, QVector provides Java-style iterators (QVectorIterator and QMutableVectorIterator) and STL-style iterators (QVector::const_iterator and QVector::iterator). In practice, these are rarely used, because you can use indexes into the QVector.

In addition to QVector, Qt also provides QVarLengthArray, a very low-level class with little functionality that is optimized for speed.

QVector does not support inserting, prepending, appending or replacing with references to its own values. Doing so will cause your application to abort with an error message.

See also
QVectorIterator, QMutableVectorIterator, QList, QLinkedList

Definition at line 64 of file qdatastream.h.

Typedefs

◆ const_iterator

template<typename T>
QVector< T >::const_iterator

The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack.

QVector provides both STL-style iterators and Java-style iterators. The STL-style const iterator is simply a typedef for "const T *" (pointer to const T).

See also
QVector::constBegin(), QVector::constEnd(), QVector::iterator, QVectorIterator

Definition at line 245 of file qvector.h.

◆ const_pointer

template<typename T>
QVector< T >::const_pointer

Typedef for const T *.

Provided for STL compatibility.

Definition at line 274 of file qvector.h.

◆ const_reference

template<typename T>
QVector< T >::const_reference

Typedef for T &.

Provided for STL compatibility.

Definition at line 276 of file qvector.h.

◆ ConstIterator

template<typename T>
QVector< T >::ConstIterator

Qt-style synonym for QVector::const_iterator.

Definition at line 279 of file qvector.h.

◆ Data

template<typename T>
typedef QVectorTypedData<T> QVector< T >::Data
private

Definition at line 107 of file qvector.h.

◆ difference_type

template<typename T>
QVector< T >::difference_type

Typedef for ptrdiff_t.

Provided for STL compatibility.

Definition at line 277 of file qvector.h.

◆ iterator

template<typename T>
QVector< T >::iterator

The QVector::iterator typedef provides an STL-style non-const iterator for QVector and QStack.

QVector provides both STL-style iterators and Java-style iterators. The STL-style non-const iterator is simply a typedef for "T *" (pointer to T).

See also
QVector::begin(), QVector::end(), QVector::const_iterator, QMutableVectorIterator

Definition at line 244 of file qvector.h.

◆ Iterator

template<typename T>
QVector< T >::Iterator

Qt-style synonym for QVector::iterator.

Definition at line 278 of file qvector.h.

◆ pointer

template<typename T>
QVector< T >::pointer

Typedef for T *.

Provided for STL compatibility.

Definition at line 273 of file qvector.h.

◆ reference

template<typename T>
QVector< T >::reference

Typedef for T &.

Provided for STL compatibility.

Definition at line 275 of file qvector.h.

◆ size_type

template<typename T>
QVector< T >::size_type

Typedef for int.

Provided for STL compatibility.

Definition at line 280 of file qvector.h.

◆ value_type

template<typename T>
QVector< T >::value_type

Typedef for T.

Provided for STL compatibility.

Definition at line 272 of file qvector.h.

Constructors and Destructors

◆ QVector() [1/4]

template<typename T>
QVector< T >::QVector ( )
inline

Constructs an empty vector.

See also
resize()

Definition at line 120 of file qvector.h.

Referenced by QVector< QPoint >::QVector().

120 : d(&QVectorData::shared_null) { d->ref.ref(); }
QBasicAtomicInt ref
Definition: qvector.h:68
QVectorData * d
Definition: qvector.h:109
static QVectorData shared_null
Definition: qvector.h:82

◆ QVector() [2/4]

template<typename T >
QVector< T >::QVector ( int  size)
explicit

Constructs a vector with an initial size of size elements.

The elements are initialized with a default-constructed value.

See also
resize()

Definition at line 411 of file qvector.h.

412 {
413  d = malloc(asize);
414  d->ref = 1;
415  d->alloc = d->size = asize;
416  d->sharable = true;
417  d->capacity = false;
419  T* b = p->array;
420  T* i = p->array + d->size;
421  while (i != b)
422  new (--i) T;
423  } else {
424  qMemSet(p->array, 0, asize * sizeof(T));
425  }
426 }
QBasicAtomicInt ref
Definition: qvector.h:68
uint sharable
Definition: qvector.h:77
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
void * qMemSet(void *dest, int c, size_t n)
Definition: qglobal.cpp:2509
QVectorData * malloc(int alloc)
Definition: qvector.h:403
uint capacity
Definition: qvector.h:78

◆ QVector() [3/4]

template<typename T>
QVector< T >::QVector ( int  size,
const T &  value 
)

Constructs a vector with an initial size of size elements.

Each element is initialized with value.

See also
resize(), fill()

Definition at line 429 of file qvector.h.

430 {
431  d = malloc(asize);
432  d->ref = 1;
433  d->alloc = d->size = asize;
434  d->sharable = true;
435  d->capacity = false;
436  T* i = p->array + d->size;
437  while (i != p->array)
438  new (--i) T(t);
439 }
QBasicAtomicInt ref
Definition: qvector.h:68
uint sharable
Definition: qvector.h:77
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
QVectorData * malloc(int alloc)
Definition: qvector.h:403
uint capacity
Definition: qvector.h:78

◆ QVector() [4/4]

template<typename T>
QVector< T >::QVector ( const QVector< T > &  other)
inline

Constructs a copy of other.

This operation takes constant time, because QVector is implicitly shared. This makes returning a QVector from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.

See also
operator=()

Definition at line 123 of file qvector.h.

123 : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); }
QBasicAtomicInt ref
Definition: qvector.h:68
uint sharable
Definition: qvector.h:77
QVectorData * d
Definition: qvector.h:109
void detach_helper()
Definition: qvector.h:336

◆ ~QVector()

template<typename T>
QVector< T >::~QVector ( )
inline

Destroys the vector.

Definition at line 124 of file qvector.h.

124 { if (!d) return; if (!d->ref.deref()) free(p); }
QBasicAtomicInt ref
Definition: qvector.h:68
QVectorData * d
Definition: qvector.h:109
void free(Data *d)
Definition: qvector.h:458
Data * p
Definition: qvector.h:113

Functions

◆ alignOfTypedData()

template<typename T>
int QVector< T >::alignOfTypedData ( ) const
inlineprivate

Definition at line 325 of file qvector.h.

326  {
327 #ifdef Q_ALIGNOF
328  return qMax<int>(sizeof(void*), Q_ALIGNOF(Data));
329 #else
330  return 0;
331 #endif
332  }
QVectorTypedData< T > Data
Definition: qvector.h:107

◆ append()

template<typename T>
void QVector< T >::append ( const T &  value)

Inserts value at the end of the vector.

Example:

QVector<QString> vector(0);
vector.append("one");
vector.append("two");
vector.append("three");
// vector: ["one", "two", "three"]

This is the same as calling resize(size() + 1) and assigning value to the new last element in the vector.

This operation is relatively fast, because QVector typically allocates more memory than necessary, so it can grow without reallocating the entire vector each time.

See also
operator<<(), prepend(), insert()

Definition at line 573 of file qvector.h.

Referenced by QFileSystemModelPrivate::_q_fileSystemChanged(), QSortFilterProxyModelPrivate::_q_sourceDataChanged(), QDeclarativeFastProperties::add(), QFontDatabasePrivate::addAppFont(), QPdfEnginePrivate::addBrushPattern(), QPdfEnginePrivate::addConstantAlphaObject(), QWidgetBackingStore::addDirtyWidget(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::addEpsilonTransition(), QIconModeViewBase::addLeaf(), QWindowsFileSystemWatcherEngine::addPaths(), ShaderEffect::addRenderTarget(), QScript::QObjectConnectionManager::addSignalHandler(), QSvgText::addText(), QBezier::addToPolygon(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::addTransition(), QRawFont::advancesForGlyphIndexes(), QRegExpEngine::anchorAlternation(), QDeclarativePropertyCache::append(), QWidgetBackingStore::appendDirtyOnScreenWidget(), QTextDocumentPrivate::appendUndoItem(), QDeclarativeBindingCompilerPrivate::buildSignalTable(), QTreeViewPrivate::calcLogicalIndices(), QScript::callQtMethod(), QPdfBaseEnginePrivate::closePrintDevice(), QTableModel::columnItems(), QAbstractItemModelPrivate::columnsAboutToBeInserted(), QAbstractItemModelPrivate::columnsAboutToBeRemoved(), QPatternist::IteratorVector::copy(), QSortFilterProxyModelPrivate::create_mapping(), QGraphicsAnchorLayoutPrivate::createItemEdges(), QPatternist::createReturnOrderBy(), createSequence(), QAbstractItemModel::decodeData(), dither_to_Mono(), QLineControl::draw(), QAlphaPaintEngine::drawPolygon(), QPdfEnginePrivate::drawTextItem(), QPdfBaseEnginePrivate::drawTextItem(), QTreeView::drawTree(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QStandardItemModel::dropMimeData(), QPatternist::XsdSchemaDebugger::dumpWildcard(), QTableModel::ensureSorted(), QOleDataObject::EnumFormatEtc(), QPatternist::TargetNode::fieldItems(), findRealWindow(), QAlphaPaintEngine::flushAndInit(), QFontEngineMacMulti::fontIndexForFontID(), QXcbWindow::glContext(), QXlibWindow::glContext(), QRawFont::glyphIndexesForString(), QTextLine::glyphs(), QSortFilterProxyModelPrivate::handle_filter_changed(), QXmlStreamAttributes::hasAttribute(), QPatternist::OptimizationPasses::Coordinator::init(), QBspTree::insert(), QTreeModel::insertColumns(), QAbstractItemModelPrivate::itemsAboutToBeMoved(), QAbstractXmlNodeModel::iterate(), QTextDocumentLayoutPrivate::layoutFlow(), QTextDocumentLayoutPrivate::layoutTable(), QTextFormat::lengthVectorProperty(), Document::load(), QPatternist::loadPattern(), mergeIterators(), QPatternist::AccelTreeBuilder< true >::namespaceBinding(), QPatternist::AccelTree::namespaceBindings(), QPdfEnginePrivate::newPage(), QDesktopWidgetImplementation::onResize(), operator>>(), QPlainTextEdit::paintEvent(), QRegExpEngine::parse(), parseAnimateTransformNode(), parseBrushValue(), QSvgHandler::parseCSStoXMLAttrs(), QCss::Parser::parseExpr(), parseNumbersList(), parseNumberTriplet(), parsePercentageList(), QPdf::patternForBrush(), QListModeViewBase::perItemScrollingPageSteps(), QListModeViewBase::perItemScrollToValue(), QPainterReplayer::process(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add(), QStack< State >::push(), q_configFromQPlatformWindowFormat(), q_createConfigAttributesFromFormat(), QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(), QDirIteratorPrivate::QDirIteratorPrivate(), QTest::qExec(), QFontEngineMacMulti::QFontEngineMacMulti(), QOleEnumFmtEtc::QOleEnumFmtEtc(), QOpenKODEWindow::QOpenKODEWindow(), qt_watch_adopted_thread(), QThreadStorageData::QThreadStorageData(), QWaylandGLContext::QWaylandGLContext(), QWaylandReadbackEglContext::QWaylandReadbackEglContext(), QWaylandXCompositeEGLContext::QWaylandXCompositeEGLContext(), QWindowsFileSystemWatcherEngineThread::QWindowsFileSystemWatcherEngineThread(), QWinSettingsPrivate::QWinSettingsPrivate(), QXmlStreamAttributes::QXmlStreamAttributes(), QInternal::registerCallback(), QSettings::registerFormat(), QMetaType::registerType(), QMetaType::registerTypedef(), QSortFilterProxyModel::removeColumns(), QSortFilterProxyModel::removeRows(), QTextHtmlParser::resolveParent(), QAbstractItemModelPrivate::rowsAboutToBeInserted(), QAbstractItemModelPrivate::rowsAboutToBeRemoved(), QSvgPaintEngine::saveGradientStops(), QCss::Scanner::scan(), QTextHtmlImporter::scanTable(), QPatternist::XsdValidatingInstanceReader::selectNodeSets(), send_targets_selection(), QXlibClipboard::sendTargetsSelection(), QTreeModel::setColumnCount(), QListWidgetItem::setData(), QTableWidgetItem::setData(), QTreeWidgetItem::setData(), QStandardItemPrivate::setItemData(), QXcbWindow::setNetWmWindowTypes(), QWidgetPrivate::setNetWmWindowTypes(), QCoreGraphicsPaintEnginePrivate::setStrokePen(), QXlibWindow::setWindowFlags(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QTableModel::sort(), QStandardItemPrivate::sortChildren(), QSortFilterProxyModelPrivate::source_items_about_to_be_removed(), QSortFilterProxyModelPrivate::source_items_inserted(), splitPolygon(), QPdfPage::streamImage(), QStyleSheetStyle::styleRules(), QBezier::toPolygon(), QPolygonF::toPolygon(), QImage::transformed(), QPatternist::NamePool::unlockedAllocateLocalName(), QPatternist::NamePool::unlockedAllocateNamespace(), QPatternist::NamePool::unlockedAllocatePrefix(), QGraphicsItem::update(), QSortFilterProxyModelPrivate::updateChildrenMapping(), QDockAreaLayoutInfo::updateSeparatorWidgets(), QDockAreaLayout::updateSeparatorWidgets(), QMYSQLResult::virtual_hook(), QConfFileSettingsPrivate::writeIniFile(), QPatternist::yyparse(), and QPdfEnginePrivate::~QPdfEnginePrivate().

574 {
575  if (d->ref != 1 || d->size + 1 > d->alloc) {
576  const T copy(t);
577  realloc(d->size, QVectorData::grow(sizeOfTypedData(), d->size + 1, sizeof(T),
580  new (p->array + d->size) T(copy);
581  else
582  p->array[d->size] = copy;
583  } else {
585  new (p->array + d->size) T(t);
586  else
587  p->array[d->size] = t;
588  }
589  ++d->size;
590 }
QBasicAtomicInt ref
Definition: qvector.h:68
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
int sizeOfTypedData()
Definition: qvector.h:320
static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive)
Definition: qvector.cpp:85
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
void realloc(int size, int alloc)
Definition: qvector.h:472

◆ at()

template<typename T >
const T & QVector< T >::at ( int  i) const
inline

Returns the item at index position i in the vector.

i must be a valid index position in the vector (i.e., 0 <= i < size()).

See also
value(), operator[]()

Definition at line 350 of file qvector.h.

Referenced by QFileSystemModelPrivate::_q_fileSystemChanged(), QGraphicsScenePrivate::_q_polishItems(), QSortFilterProxyModelPrivate::_q_sourceDataChanged(), QSortFilterProxyModelPrivate::_q_sourceHeaderDataChanged(), QDeclarativeFastProperties::accessor(), QMenuPrivate::actionAt(), QMenuPrivate::actionRect(), QMetaObject::activate(), QRegExpEngine::Box::addAnchorsToEngine(), QFontDatabasePrivate::addAppFont(), QRegExpEngine::addCatTransitions(), QXmlStreamReader::addExtraNamespaceDeclarations(), QPixmapIconEngine::addFile(), QGridLayoutPrivate::addHfwData(), QPdfEnginePrivate::addImage(), QIconModeViewBase::addLeaf(), QRegExpEngine::addPlusTransitions(), QPainterPath::addPolygon(), QPainterPath::addRegion(), QMenuPrivate::adjustMenuSizeForScreen(), QTreeViewPrivate::adjustViewOptionsForIndex(), QImage::allGray(), QRegExpEngine::anchorAlternation(), QRegExpEngine::anchorConcatenation(), QTextHtmlParserNode::applyCssDeclarations(), QSyntaxHighlighterPrivate::applyFormatChanges(), QFormLayoutPrivate::arrangeWidgets(), QOCIResultPrivate::bindValues(), QAhiScreen::blit(), QTransformedScreen::blit(), blit_template(), QSortFilterProxyModelPrivate::build_source_to_proxy_mapping(), QPatternist::CachingIterator::CachingIterator(), QBoxLayoutPrivate::calcHfw(), QTreeViewPrivate::calcLogicalIndices(), QTextTableData::calcRowPosition(), QFormLayoutPrivate::calcSizeHints(), QScript::callQtMethod(), QSortFilterProxyModelPrivate::can_create_mapping(), QRegionPrivate::canPrepend(), QRegExpEngine::Box::cat(), QRegExpEngine::Box::catAnchor(), QTextTableData::cellPosition(), QGridLayoutPrivate::cellRect(), QTextTableData::cellWidth(), checkGrayscale(), QWinSettingsPrivate::children(), QDesktopWidgetPrivate::cleanup(), QWizardPage::cleanupPage(), QDeclarativePropertyCache::clear(), QTableModel::clear(), QTableModel::clearContents(), closestMatch(), QImage::color(), QTextTableCell::column(), QStandardItemModelPrivate::columnsRemoved(), QPaintBuffer::commandDescription(), QScreen::compose(), QMetaType::construct(), convert_indexed8_to_ARGB_PM_inplace(), convert_indexed8_to_RGB16_inplace(), convert_indexed8_to_RGB_inplace(), convert_Indexed8_to_X32(), convert_Mono_to_X32(), convert_RGB_to_Indexed8(), QPatternist::XsdTypeChecker::convertToQName(), QPatternist::CachingIterator::copy(), QDeclarativePropertyCache::copy(), QDockWidgetLayout::count(), QSqlRecordPrivate::createField(), createPolygonNode(), createPolylineNode(), createSequence(), QFontSubset::createToUnicodeMap(), cubicTo_clipped(), QSqlCachedResult::data(), QODBCResult::data(), QListWidgetItem::data(), QTableWidgetItem::data(), QTreeWidgetItem::data(), declarations(), QCss::StyleSelector::declarationsForNode(), QAbstractItemModel::decodeData(), QPatternist::AccelTree::depth(), QMetaType::destroy(), QWidgetBackingStore::dirtyOnScreenWidgetsRemoveAll(), QWidgetBackingStore::dirtyRegion(), QWidgetBackingStore::dirtyWidgetsRemoveAll(), QPatternist::NamePool::displayName(), QPatternist::NamePool::displayPrefix(), QGridLayoutPrivate::distribute(), distributeMultiBox(), dither_to_Mono(), QTextLayout::draw(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QPainter::drawChord(), QTextDocumentLayoutPrivate::drawFrame(), QGraphicsScenePrivate::drawItemHelper(), QBlitterPaintEngine::drawPixmap(), QTreeView::drawRow(), QTextDocumentLayoutPrivate::drawTableCell(), QPainter::drawText(), QTreeView::drawTree(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QStandardItemModel::dropMimeData(), AnchorData::dump(), QGridLayoutEngine::dump(), QObject::dumpObjectInfo(), QPatternist::XsdSchemaDebugger::dumpWildcard(), QTextHtmlExporter::emitTable(), QRegion::ensureHandle(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QGLColormap::entryColor(), QGLColormap::entryRgb(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::epsilonClosure(), QPatternist::EvaluationCache< IsForGlobal >::evaluateSequence(), QDB2Result::exec(), QSQLiteResult::exec(), QSymSQLResult::exec(), QODBCResult::exec(), QSqlResult::execBatch(), QScript::QObjectConnectionManager::execute(), QCoreApplication::exit(), QProxyScreen::exposeRegion(), QDirectFBScreen::exposeRegion(), QScreen::exposeRegion(), QWinSettingsPrivate::fileName(), QGL2PaintEngineExPrivate::fill(), QImage::fill(), QVGCompositionHelper::fillBackground(), QX11PaintEnginePrivate::fillPath(), QBlitterPaintEngine::fillRect(), QBlitterPaintEnginePrivate::fillRect(), QVGPaintEngine::fillRegion(), fillRegion(), QGridLayoutEngine::fillRowData(), QGL2PaintEngineExPrivate::fillStencilWithVertexArray(), QSortFilterProxyModelPrivate::filter_changed(), QGLColormap::findNearest(), findRealWindow(), QPatternist::ApplyTemplate::findTemplate(), QRegExpEngine::finishAtom(), fix_color_table(), QDirectFBScreen::flipSurface(), QDirectFbWindowSurface::flush(), QXcbWindowSurface::flush(), QMacWindowSurface::flush(), QWidgetBackingStore::flush(), QGLWindowSurface::flush(), QRasterWindowSurface::flush(), QAlphaPaintEngine::flushAndInit(), QPSPrintEnginePrivate::flushPage(), QTextEngine::format(), QTextEngine::formatIndex(), QPdf::generateDashes(), QWinSettingsPrivate::get(), QVariantAnimationPrivate::getInterpolator(), QFontSubset::getReverseMap(), QGLEngineShaderManager::getUniformLocation(), QSortFilterProxyModelPrivate::handle_filter_changed(), QPathClipper::handleCrossingEdges(), QPatternist::XSLTTokenizer::handleStandardAttributes(), QPatternist::XSLTTokenizer::handleValidationAttributes(), QPatternist::AccelTree::hasChildren(), QPatternist::AccelTree::hasParent(), QPatternist::AccelTree::hasPrefix(), QStyleSheetStyle::hasStyleRule(), QTableModel::headerData(), QHeaderViewPrivate::headerLength(), QHeaderViewPrivate::headerSectionCount(), QRegExpEngine::heuristicallyChooseHeuristic(), QRegExpCharClass::in(), QTableModel::index(), QDesktopWidgetPrivate::init(), QStaticTextPrivate::init(), QConfFileSettingsPrivate::initFormat(), QClipData::initialize(), QTriangulator< T >::initialize(), QSortFilterProxyModelPrivate::insert_source_items(), QSortFilterProxyModel::insertColumns(), QSortFilterProxyModel::insertRows(), QPatternist::XSLTTokenizer::insideSequenceConstructor(), QDirModelPrivate::invalidate(), QFontDatabasePrivate::isApplicationFont(), QXmlSerializer::isBindingInScope(), QWizardPage::isComplete(), QPatternist::AccelTree::isCompressed(), QImage::isGrayscale(), QTreeViewPrivate::isItemHiddenOrDisabled(), QSqlCachedResult::isNull(), QODBCResult::isNull(), QBrush::isOpaque(), QMetaType::isRegistered(), QObjectPrivate::isSender(), QTableModel::item(), QDockWidgetLayout::itemAt(), QListModel::itemData(), QTreeModel::itemData(), QTableModel::itemData(), QDockWidgetLayout::itemForRole(), QPatternist::AccelTree::kind(), QTextDocumentLayoutPrivate::layoutCell(), QTextDocumentLayoutPrivate::layoutTable(), QMetaType::load(), QFontEngineMultiXLFD::loadEngine(), QFontEngineMultiFT::loadEngine(), QFontEngineMultiWin::loadEngine(), QFontEngineMultiQPA::loadEngine(), QFontEngineMultiQWS::loadEngine(), QHeaderViewPrivate::logicalIndex(), ShaderEffectItem::lookThroughShaderCode(), make_widget_eventUPP(), mapProjective(), QRegExpMatchState::matchHere(), QTextFormat::merge(), mergeInto(), QDeclarativePropertyCache::method(), QStandardItemModel::mimeData(), QVNCCursor::move(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::move(), QPatternist::AccelTree::name(), QPatternist::AccelTreeBuilder< true >::namespaceBinding(), QPatternist::AccelTree::namespaceBindings(), QAbstractXmlNodeModel::namespaceForPrefix(), QOleEnumFmtEtc::Next(), qLess< Item::List >::operator()(), operator<<(), operator>>(), QRegExpEngine::Box::orx(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::outputGraph(), QOCIResultPrivate::outValues(), QDeclarativePropertyCache::overrideData(), QDeclarativePaintedItem::paint(), QScreen::paintBackground(), QBlittablePixmapData::paintEngine(), QTableView::paintEvent(), QMdiArea::paintEvent(), QDirModel::parent(), QPatternist::AccelTree::parent(), QRegExpEngine::parse(), parseColorValue(), parseCoreNode(), parseCSStoXMLAttrs(), parseShorthandBackgroundProperty(), parseShorthandFontProperty(), parseStopNode(), QPdf::patternForBrush(), QListModeViewBase::perItemScrollingPageSteps(), QListModeViewBase::perItemScrollToValue(), QImage::pixel(), QStyleSheetStyle::polish(), populate_database(), QPatternist::AccelTree::postNumber(), QPaintBuffer::processCommands(), QDashStroker::processCurrentSubpath(), QDeclarativePropertyCache::property(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add(), QSortFilterProxyModelPrivate::proxy_item_range(), QSortFilterProxyModelPrivate::proxy_to_source(), q_configFromQPlatformWindowFormat(), q_reduceConfigAttributes(), qBinarySearch(), qCreateParamString(), qDrawPlainRect(), QFontEngineMultiFT::QFontEngineMultiFT(), qGeomCalc(), qMetaTypeCustomType_unlocked(), QOleEnumFmtEtc::QOleEnumFmtEtc(), QPolygonF::QPolygonF(), QRenderRule::QRenderRule(), QSvgAttributes::QSvgAttributes(), qt_adopted_thread_watcher_function(), qt_fetchPixel< QImage::Format_Indexed8 >(), qt_fetchPixel< QImage::Format_Mono >(), qt_fetchPixel< QImage::Format_MonoLSB >(), qt_mac_desktopSize(), qt_mac_fill_background(), qt_mac_post_retranslateAppMenu(), qt_region_strictContains(), QThreadStorageData::QThreadStorageData(), query_colormap(), QPatternist::XSLTTokenizer::queueNamespaceDeclarations(), QVectorPathConverter::QVectorPathData::QVectorPathData(), qVectorToSet(), QRasterPaintEnginePrivate::rasterizeLine_dashed(), QOCICols::readPiecewise(), QGridLayoutPrivate::recalcHFW(), QFormLayoutPrivate::recalcHFW(), QObjectPrivate::receiverList(), QObject::receivers(), QSqlTableModelPrivate::record(), QStateMachinePrivate::registerSignalTransition(), QSortFilterProxyModelPrivate::remove_source_items(), QTableModel::removeColumns(), QSortFilterProxyModel::removeColumns(), QTableModel::removeRows(), QSortFilterProxyModel::removeRows(), QScript::QObjectConnectionManager::removeSignalHandler(), QHeaderViewPrivate::removeSpans(), QStyleSheetStyle::renderRule(), QDesktopWidget::resizeEvent(), QTextEngine::resolveAdditionalFormats(), QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(), QImage::rgbSwapped(), QTextTableCell::row(), QStandardItemModelPrivate::rowsRemoved(), QWindowsFileSystemWatcherEngineThread::run(), QMetaType::save(), QSvgPaintEngine::saveGradientStops(), QTextHtmlImporter::scanTable(), QDirectFbWindowSurface::scroll(), QXcbWindowSurface::scroll(), QXlibWindowSurface::scroll(), QRasterWindowSurface::scroll(), QWSMemorySurface::scroll(), QGraphicsItem::scroll(), QMenuPrivate::scrollMenu(), QWidgetPrivate::scrollRect(), QHeaderViewPrivate::sectionSpanIndex(), QTreeViewPrivate::select(), QPatternist::AccelTree::sendNamespaces(), QAbstractXmlNodeModel::sendNamespaces(), separatorMoveHelper(), QVNCCursor::set(), QClipData::setClipRegion(), QGradient::setColorAt(), QImage::setColorTable(), QPainterPathStroker::setDashPattern(), QListWidgetItem::setData(), QTableWidgetItem::setData(), QTreeWidgetItem::setData(), QMenuPrivate::setFirstActionActive(), setFontFamilyFromValues(), QBoxLayout::setGeometry(), QDockAreaLayout::setGrid(), QTableModel::setHeaderData(), QTableModel::setHorizontalHeaderItem(), QTableModel::setItem(), QTextHtmlParserNode::setListStyle(), QStandardItemPrivate::setModel(), QWizard::setPage(), QPatternist::NamespaceSupport::setPrefixes(), QStyleSheetStyle::setProperties(), QTextFormat::setProperty(), QGradient::setStops(), QCoreGraphicsPaintEnginePrivate::setStrokePen(), setTextDecorationFromValues(), QCosmeticStroker::setup(), QRegExpEngine::Box::setupHeuristics(), QGridLayoutPrivate::setupHfwLayoutData(), QFormLayoutPrivate::setupHfwLayoutData(), QGridLayoutPrivate::setupSpacings(), QTableModel::setVerticalHeaderItem(), QPainter::setViewTransformEnabled(), QPatternist::AccelTree::size(), QTreeView::sizeHintForColumn(), QAhiScreen::solidFill(), QDirectFBScreen::solidFill(), solidFill_template(), QTableModel::sort(), QStandardItemPrivate::sortChildren(), QSortFilterProxyModelPrivate::source_to_proxy(), splitPolygon(), QPatternist::DocumentProjector::startElement(), QWindowsFileSystemWatcherEngineThread::stop(), QPatternist::AccelTreeResourceLoader::streamToReceiver(), QPatternist::NamePool::stringForLocalName(), QPatternist::NamePool::stringForNamespace(), QPatternist::NamePool::stringForPrefix(), QRasterPaintEngine::stroke(), QWidgetBackingStore::sync(), QDockWidgetLayout::takeAt(), QTableModel::takeHorizontalHeaderItem(), QTableModel::takeVerticalHeaderItem(), QPainterPath::toFillPolygons(), QX11PixmapData::toImage(), QPatternist::NamePool::toLexical(), QApplicationPrivate::translateTouchEvent(), QPixmapIconEngine::tryMatch(), QMetaType::typeName(), QStateMachinePrivate::unregisterSignalTransition(), QMetaType::unregisterType(), QOpenGLPaintEngine::updateClipRegion(), QOpenGLPaintEnginePrivate::updateDepthClip(), updateRedirectedToGraphicsProxyWidget(), QGraphicsViewPrivate::updateRegion(), QGraphicsView::updateScene(), QDockAreaLayoutInfo::updateSeparatorWidgets(), QDockAreaLayout::updateSeparatorWidgets(), ShaderEffectItem::updateShaderProgram(), QPdfBaseEngine::updateState(), QDockAreaLayoutInfo::usedSeparatorWidgets(), QDockAreaLayout::usedSeparatorWidgets(), QObject::userData(), QPatternist::XsdValidatingInstanceReader::validateKeyIdentityConstraint(), QMYSQLResult::virtual_hook(), QHeaderViewPrivate::visualIndex(), QWindowsFileSystemWatcherEngineThread::wakeup(), QDockWidgetLayout::widgetForRole(), QTiffHandler::write(), QPixmapIconEngine::write(), QXmlStreamWriter::writeAttributes(), QXmlStreamWriter::writeCurrentToken(), QTextOdfWriter::writeFormats(), QWinSettingsPrivate::writeHandle(), QConfFileSettingsPrivate::writeIniFile(), QPdfEnginePrivate::writePage(), QPatternist::yyparse(), QFontEngineMacMulti::~QFontEngineMacMulti(), QOleEnumFmtEtc::~QOleEnumFmtEtc(), QPaintBufferPrivate::~QPaintBufferPrivate(), QPainterPrivate::~QPainterPrivate(), QPdfEnginePrivate::~QPdfEnginePrivate(), QWidgetBackingStore::~QWidgetBackingStore(), QWindowsFileSystemWatcherEngineThread::~QWindowsFileSystemWatcherEngineThread(), and QWinSettingsPrivate::~QWinSettingsPrivate().

351 { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::at", "index out of range");
352  return p->array[i]; }
Data * p
Definition: qvector.h:113
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ back() [1/2]

template<typename T>
QVector::reference QVector< T >::back ( )
inline

This function is provided for STL compatibility.

It is equivalent to last().

Definition at line 289 of file qvector.h.

Referenced by QSvgText::addText(), QSvgText::draw(), QRBTree< int >::order(), parseStopNode(), and QSvgPaintEngine::saveGradientStops().

289 { return last(); }
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262

◆ back() [2/2]

template<typename T>
QVector::const_reference QVector< T >::back ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 290 of file qvector.h.

290 { return last(); }
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262

◆ begin() [1/2]

template<typename T>
QVector::iterator QVector< T >::begin ( )
inline

Returns an STL-style iterator pointing to the first item in the vector.

See also
constBegin(), end()

Definition at line 247 of file qvector.h.

Referenced by QFileSystemModelPrivate::_q_fileSystemChanged(), QSortFilterProxyModelPrivate::_q_sourceDataChanged(), QDBusAdaptorConnector::addAdaptor(), QXcbWindowSurface::beginPaint(), QXlibWindowSurface::beginPaint(), QX11WindowSurface::beginPaint(), QRasterWindowSurface::beginPaint(), QWSMemorySurface::beginPaint(), QListViewPrivate::closestIndex(), QPathClipper::doClip(), QTextDocumentLayoutPrivate::drawFlow(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QPatternist::TemplateMode::finalize(), QTextDocumentLayoutPrivate::frameIteratorForYPosition(), QPathClipper::handleCrossingEdges(), huntAndDestroy(), QIconModeViewBase::itemsRect(), QTextDocumentLayoutPrivate::layoutFlow(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items(), qtKey2CocoaKey(), QDBusConnection::registerObject(), QListViewPrivate::removeCurrentAndDisabled(), QSortFilterProxyModel::removeRows(), QListViewPrivate::selection(), QTableModel::setItem(), QVariantAnimationPrivate::setValueAt(), QTableModel::sort(), QSortFilterProxyModelPrivate::sort_source_rows(), QStandardItemPrivate::sortChildren(), splitPolygon(), QDBusConnection::unregisterObject(), QSortFilterProxyModelPrivate::updateChildrenMapping(), and QVariantAnimationPrivate::valueAt().

247 { detach(); return p->array; }
void detach()
Definition: qvector.h:147
Data * p
Definition: qvector.h:113

◆ begin() [2/2]

template<typename T>
QVector::const_iterator QVector< T >::begin ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 248 of file qvector.h.

248 { return p->array; }
Data * p
Definition: qvector.h:113

◆ capacity()

template<typename T>
int QVector< T >::capacity ( ) const
inline

Returns the maximum number of items that can be stored in the vector without forcing a reallocation.

The sole purpose of this function is to provide a means of fine tuning QVector's memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the vector, call size().

See also
reserve(), squeeze()

Definition at line 143 of file qvector.h.

Referenced by QGraphicsViewPrivate::allocStyleOptionsArray().

143 { return d->alloc; }
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109

◆ clear()

template<typename T >
void QVector< T >::clear ( )
inline

Removes all the elements from the vector and releases the memory used by the vector.

Definition at line 347 of file qvector.h.

Referenced by QGraphicsScenePrivate::_q_polishItems(), QDeclarativeTextLayout::beginLayout(), QSqlCachedResult::cacheNext(), QSqlCachedResultPrivate::cleanup(), QGraphicsSceneBspTree::clear(), QDeclarativePropertyCache::clear(), QDeclarativeTextLayout::clearLayout(), QTextEngine::clearLineData(), QShortcutMap::clearSequence(), QPatternist::ReturnOrderBy::compress(), QBspTree::destroy(), dither_to_Mono(), QGraphicsScenePrivate::drawItemHelper(), QODBCResult::exec(), QPicture::exec(), QSQLite2ResultPrivate::fetchNext(), QSQLiteResultPrivate::fetchNext(), QShortcutMap::find(), QWidgetBackingStore::flush(), QAlphaPaintEngine::flushAndInit(), QXlibWindow::getNetWmState(), getNetWmState(), QXmlSimpleReaderPrivate::init(), QXmlStreamReaderPrivate::init(), QXmlSimpleReaderPrivate::initData(), QXmlSimpleReaderPrivate::initIncrementalParsing(), QTextEngine::invalidate(), QTextDocumentLayoutPrivate::layoutFlow(), QTextDocumentLayoutPrivate::layoutTable(), QODBCResult::nextResult(), QDesktopWidgetImplementation::onResize(), operator>>(), QXmlStreamReaderPrivate::parse(), QRegExpEngine::parse(), QXmlSimpleReaderPrivate::parseBeginOrContinue(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add(), qDrawShadePanel(), qt_cleanup_painter_state(), QPixmapIconEngine::read(), QSyntaxHighlighterPrivate::reformatBlocks(), QODBCResult::reset(), ShaderEffectItem::reset(), QTextEngine::resolveAdditionalFormats(), QWizard::setPage(), QGlyphRun::setRawData(), QGradient::setStops(), QPen::setStyle(), QFormLayoutPrivate::setupHfwLayoutData(), QFormLayoutPrivate::setupVerticalLayoutData(), QComboBox::showPopup(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QWidgetBackingStore::sync(), QPainterPath::toFillPolygons(), QPainterPath::toSubpathPolygons(), QDBusConnection::unregisterObject(), QGraphicsItem::update(), QDockAreaLayoutInfo::updateSeparatorWidgets(), QDBusConnectionPrivate::~QDBusConnectionPrivate(), QFontEngineMacMulti::~QFontEngineMacMulti(), and QOleEnumFmtEtc::~QOleEnumFmtEtc().

348 { *this = QVector<T>(); }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64

◆ constBegin()

template<typename T>
QVector::const_iterator QVector< T >::constBegin ( ) const
inline

◆ constData()

template<typename T>
const T * QVector< T >::constData ( ) const
inline

Returns a const pointer to the data stored in the vector.

The pointer can be used to access the items in the vector. The pointer remains valid as long as the vector isn't reallocated.

This function is mostly useful to pass a vector to a function that accepts a plain C++ array.

See also
data(), operator[]()

Definition at line 154 of file qvector.h.

Referenced by QRegionPrivate::append(), ShaderEffectItem::bindGeometry(), QTextEngine::boundingBox(), QDeclarativeBindingCompilerPrivate::buildSignalTable(), QRegionPrivate::canAppend(), QRegionPrivate::canPrepend(), QPaintBuffer::commandDescription(), QPainter::drawConvexPolygon(), QPainter::drawLines(), QPainter::drawPoints(), QPainter::drawPolygon(), QPainter::drawPolyline(), QPainter::drawRects(), EqualRegion(), QRasterPaintEngine::fillPolygon(), QGlyphRun::glyphIndexes(), QStaticTextPrivate::init(), isEmptyHelper(), QMatrix::map(), QTransform::map(), mergeInto(), miRegionOp(), miSetExtents(), parseShorthandBackgroundProperty(), QGlyphRun::positions(), QRegionPrivate::prepend(), QDeclarativeBindingCompiler::program(), q_configFromQPlatformWindowFormat(), QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(), qglx_findConfig(), QOpenKODEWindow::QOpenKODEWindow(), QRegion::QRegion(), qt_adopted_thread_watcher_function(), qt_bitmapToRegion(), qt_regionToPath(), QWaylandGLContext::QWaylandGLContext(), QWaylandReadbackEglContext::QWaylandReadbackEglContext(), QWaylandXCompositeEGLContext::QWaylandXCompositeEGLContext(), RectInRegion(), QWSDisplay::repaintRegion(), QWizardField::resolve(), QWindowsFileSystemWatcherEngineThread::run(), QWSRegionEvent::setData(), QWSRegionCommand::setData(), QWSEmbedCommand::setData(), QOpenKODEWindow::setGeometry(), QGlyphRun::setGlyphIndexes(), QXcbWindow::setNetWmWindowTypes(), QWidgetPrivate::setNetWmWindowTypes(), QGlyphRun::setPositions(), QDBusPendingCallPrivate::setReplyCallback(), QPainter::testRenderHint(), QTextEngine::tightBoundingBox(), and QTextEngine::width().

154 { return p->array; }
Data * p
Definition: qvector.h:113

◆ constEnd()

template<typename T>
QVector::const_iterator QVector< T >::constEnd ( ) const
inline

◆ contains()

template<typename T>
bool QVector< T >::contains ( const T &  value) const

◆ count() [1/2]

template<typename T>
int QVector< T >::count ( const T &  value) const

Returns the number of occurrences of value in the vector.

This function requires the value type to have an implementation of operator==().

See also
contains(), indexOf()

Definition at line 742 of file qvector.h.

Referenced by QFileSystemModelPrivate::_q_fileSystemChanged(), QGraphicsScenePrivate::_q_polishItems(), QSortFilterProxyModelPrivate::_q_sourceDataChanged(), QMenuPrivate::actionAt(), QDeclarativeFastProperties::add(), QFontDatabasePrivate::addAppFont(), QObjectPrivate::addConnection(), QPixmapIconEngine::addFile(), QIconModeViewBase::addLeaf(), QWindowsFileSystemWatcherEngine::addPaths(), QDeclarativePropertyCache::append(), QTextHtmlParserNode::applyCssDeclarations(), QSyntaxHighlighterPrivate::applyFormatChanges(), QTreeViewPrivate::below(), QOCIResultPrivate::bindValues(), QDeclarativeBindingCompilerPrivate::buildSignalTable(), QBoxLayoutPrivate::calcHfw(), QTreeViewPrivate::calcLogicalIndices(), QTextEngine::calculateTabWidth(), cgColorForQColor(), QObjectPrivate::cleanConnectionLists(), QWizardPage::cleanupPage(), QDeclarativePropertyCache::clear(), QTableModel::clear(), QTableModel::clearContents(), QTableModel::columnCount(), QMetaObjectPrivate::connect(), QSqlRecordPrivate::contains(), QPatternist::XsdTypeChecker::convertToQName(), QVariantAnimationPrivate::convertValues(), QDeclarativePropertyCache::copy(), QDockWidgetLayout::count(), createPolygonNode(), createPolylineNode(), createSequence(), QPatternist::AccelTreeBuilder< true >::currentDepth(), QListWidgetItem::data(), QTableWidgetItem::data(), QTreeWidgetItem::data(), declarations(), QCss::StyleSelector::declarationsForNode(), QAbstractItemModel::decodeData(), QMetaObjectPrivate::disconnect(), QPatternist::DocumentProjector::DocumentProjector(), QListModeViewBase::dragMoveEvent(), ShaderEffect::draw(), QDeclarativeTextLayout::draw(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QTreeView::drawRow(), QTreeView::drawTree(), QStandardItemModel::dropMimeData(), QListModeViewBase::dropOn(), AnchorData::dump(), QGridLayoutEngine::dump(), QObject::dumpObjectInfo(), QTextHtmlExporter::emitTable(), QTableModel::ensureSorted(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::epsilonClosure(), QIBaseResult::exec(), QDB2Result::exec(), QSQLiteResult::exec(), QSymSQLResult::exec(), QODBCResult::exec(), QSqlResult::execBatch(), QOCICols::execBatch(), QSQLite2ResultPrivate::fetchNext(), QSQLiteResultPrivate::fetchNext(), QOpenGLPaintEnginePrivate::fillPath(), QGridLayoutEngine::fillRowData(), QPatternist::ApplyTemplate::findTemplate(), QFontEngineMacMulti::fontIndexForFontID(), QGradientCache::generateGradientColorTable(), QGLPathMaskGenerator::generateTrapezoids(), QSortFilterProxyModelPrivate::handle_filter_changed(), QPatternist::XSLTTokenizer::handleStandardAttributes(), QPatternist::XSLTTokenizer::handleValidationAttributes(), QSortFilterProxyModel::hasChildren(), QStyleSheetStyle::hasStyleRule(), QTableModel::headerData(), QHeaderViewPrivate::headerLength(), QHeaderViewPrivate::headerSectionCount(), ShaderEffect::hideOriginal(), QTableModel::index(), QHeaderViewPrivate::initializeIndexMapping(), QTableModel::insertColumns(), QSortFilterProxyModel::insertColumns(), insertOrRemoveItems(), QTableModel::insertRows(), QSortFilterProxyModel::insertRows(), QXmlSimpleReaderPrivate::insertXmlRef(), QPatternist::XSLTTokenizer::insideSequenceConstructor(), QListModeViewBase::intersectingSet(), QDirModelPrivate::invalidate(), QFontDatabasePrivate::isApplicationFont(), QWizardPage::isComplete(), QTreeViewPrivate::isItemHiddenOrDisabled(), QMetaType::isRegistered(), QTableModel::isValid(), QDockWidgetLayout::itemAt(), QListModel::itemData(), QTreeModel::itemData(), QTableModel::itemData(), QTextDocumentLayoutPrivate::layoutTable(), QBspTree::leafCount(), QPatternist::AccelTree::maximumPreNumber(), QTextFormat::merge(), QDeclarativePropertyCache::method(), QTreeWidget::mimeData(), QStandardItemModel::mimeData(), QPatternist::NamePool::NamePool(), QPatternist::AccelTreeBuilder< true >::namespaceBinding(), QOleEnumFmtEtc::Next(), qLess< Item::List >::operator()(), operator<<(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::outputGraph(), QOCIResultPrivate::outValues(), QDeclarativePaintedItem::paint(), QDirModel::parent(), QDeclarativeStyledTextPrivate::parse(), QRegExpEngine::parse(), parseColorValue(), parseCoreNode(), parseCSStoXMLAttrs(), parseShorthandBackgroundProperty(), parseShorthandFontProperty(), parseStopNode(), QListModeViewBase::perItemScrollingPageSteps(), QPixmapIconEngine::pixmap(), QStyleSheetStyle::polish(), QSvgHandler::popColor(), QDeclarativeTextLayout::prepare(), QDeclarativeBindingCompiler::program(), QDeclarativePropertyCache::property(), QSortFilterProxyModelPrivate::proxy_item_range(), QSvgHandler::pushColorCopy(), qCreateParamString(), qMetaTypeCustomType_unlocked(), QOleEnumFmtEtc::QOleEnumFmtEtc(), QRegion::QRegion(), QRenderRule::QRenderRule(), QSvgAttributes::QSvgAttributes(), qt_adopted_thread_watcher_function(), qt_bitmapToRegion(), qt_mac_post_retranslateAppMenu(), QThreadStorageData::QThreadStorageData(), QPatternist::XSLTTokenizer::queueNamespaceDeclarations(), rasterFallbackWarn(), QWSLinuxTPMouseHandlerPrivate::readMouseData(), QVariantAnimationPrivate::recalculateCurrentInterval(), QSqlTableModelPrivate::record(), QTableModel::removeColumns(), QTextTable::removeColumns(), QSortFilterProxyModel::removeColumns(), QTableModel::removeRows(), QSortFilterProxyModel::removeRows(), QStyleSheetStyle::renderRule(), QWSDisplay::repaintRegion(), QXmlSimpleReaderPrivate::reportEndEntities(), QFutureInterface< T >::reportResults(), QWizardField::resolve(), QTextEngine::resolveAdditionalFormats(), QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(), QTableModel::rowCount(), QWindowsFileSystemWatcherEngineThread::run(), QTextHtmlImporter::scanTable(), QTreeView::scrollContentsBy(), QMenuPrivate::scrollMenu(), QHeaderViewPrivate::sectionSpanIndex(), QTreeViewPrivate::select(), QPatternist::XsdValidatingInstanceReader::selectNodeSets(), QWSCalibratedMouseHandler::sendFiltered(), QPatternist::AccelTree::sendNamespaces(), separatorMoveHelper(), QSvgAnimateTransform::setArgs(), QTableModel::setColumnCount(), QListWidgetItem::setData(), QTableWidgetItem::setData(), QTreeWidgetItem::setData(), QWSRegionCommand::setData(), QWSEmbedCommand::setData(), setFontFamilyFromValues(), QBoxLayout::setGeometry(), QTableModel::setHorizontalHeaderItem(), QTableModel::setItem(), QTextHtmlParserNode::setListStyle(), QStandardItemPrivate::setModel(), QXcbWindow::setNetWmWindowTypes(), QWidgetPrivate::setNetWmWindowTypes(), QWizard::setPage(), QVGPaintEnginePrivate::setPenParams(), QPatternist::NamespaceSupport::setPrefixes(), QStyleSheetStyle::setProperties(), QGridLayoutEngine::setRowAlignment(), QTableModel::setRowCount(), QGridLayoutEngine::setRowSizeHint(), QGridLayoutEngine::setRowSpacing(), QGridLayoutEngine::setRowStretchFactor(), QVGCompositionHelper::setScissor(), setTextDecorationFromValues(), QTableModel::setVerticalHeaderItem(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QTreeView::sizeHintForColumn(), QOleEnumFmtEtc::Skip(), QTableModel::sort(), QStandardItemPrivate::sortChildren(), QSortFilterProxyModelPrivate::source_items_inserted(), QTransform::squareToQuad(), QStyleSheetStyle::styleRules(), QDockWidgetLayout::takeAt(), QTableModel::takeHorizontalHeaderItem(), QTableModel::takeVerticalHeaderItem(), QTextLine::textLength(), QApplicationPrivate::translateTouchEvent(), QPixmapIconEngine::tryMatch(), QPatternist::OrderBy::typeCheck(), QMetaType::typeName(), QPatternist::NamePool::unlockedAllocateLocalName(), QPatternist::NamePool::unlockedAllocateNamespace(), QPatternist::NamePool::unlockedAllocatePrefix(), QMetaType::unregisterType(), QGLContext::updatePaintDevice(), updateRedirectedToGraphicsProxyWidget(), ShaderEffect::updateRenderTargets(), QVGPaintEngine::updateScissor(), QDockAreaLayoutInfo::usedSeparatorWidgets(), QDockAreaLayout::usedSeparatorWidgets(), QPatternist::XsdValidatingInstanceReader::validateKeyIdentityConstraint(), QMYSQLResult::virtual_hook(), QPatternist::yyparse(), QFontEngineMacMulti::~QFontEngineMacMulti(), QObject::~QObject(), and QOleEnumFmtEtc::~QOleEnumFmtEtc().

743 {
744  int c = 0;
745  T* b = p->array;
746  T* i = p->array + d->size;
747  while (i != b)
748  if (*--i == t)
749  ++c;
750  return c;
751 }
unsigned char c[8]
Definition: qnumeric_p.h:62
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70

◆ count() [2/2]

template<typename T>
int QVector< T >::count ( ) const
inline

Same as size().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 259 of file qvector.h.

259 { return d->size; }
QVectorData * d
Definition: qvector.h:109
int size
Definition: qvector.h:70

◆ data() [1/2]

template<typename T>
T * QVector< T >::data ( )
inline

Returns a pointer to the data stored in the vector.

The pointer can be used to access and modify the items in the vector.

Example:

QVector<int> vector(10);
int *data = vector.data();
for (int i = 0; i < 10; ++i)
data[i] = 2 * i;

The pointer remains valid as long as the vector isn't reallocated.

This function is mostly useful to pass a vector to a function that accepts a plain C++ array.

See also
constData(), operator[]()

Definition at line 152 of file qvector.h.

Referenced by QRawFont::advancesForGlyphIndexes(), QGraphicsViewPrivate::allocStyleOptionsArray(), QRegionPrivate::append(), QScript::callQtMethod(), QX11PaintEnginePrivate::clipPolygon_dev(), QPixmap::clut(), QImageTextureGlyphCache::createTextureData(), QVertexIndexVector::data(), QPainter::drawChord(), QPaintEngine::drawEllipse(), QX11PaintEngine::drawPath(), QOCICols::execBatch(), QOpenGLPaintEnginePrivate::fillPath(), findRealWindow(), flushRow(), QGraphicsViewPrivate::freeStyleOptionsArray(), QX11PixmapData::fromImage(), QGLPathMaskGenerator::generateTrapezoids(), QXlibWindow::getNetWmState(), getNetWmState(), QXcbWindow::glContext(), QXlibWindow::glContext(), QGlyphRun::glyphIndexes(), QRegionPrivate::intersect(), QMatrix::map(), QTransform::map(), QTransformedScreen::mapFromDevice(), QTransformedScreen::mapToDevice(), QRegExpMatchState::matchHere(), mergeInto(), miCoalesce(), miIntersectO(), miRegionOp(), miSubtractNonO1(), miSubtractO(), miUnionNonO(), miUnionO(), OffsetRegion(), QStack< State >::pop(), QGlyphRun::positions(), QDeclarativeTextLayout::prepare(), QRegionPrivate::prepend(), PtsToRegion(), QOpenKODEWindow::QOpenKODEWindow(), qstring_to_xtp(), qt_mac_desktopSize(), send_targets_selection(), QXlibClipboard::sendTargetsSelection(), QWSEmbedEvent::setData(), QOpenKODEWindow::setGeometry(), QCoreGraphicsPaintEnginePrivate::setStrokePen(), QVGPaintEnginePrivate::setupColorRamp(), QPainter::setViewTransformEnabled(), QXlibWindow::setWindowFlags(), QGridLayoutEngine::sizeHint(), QStack< State >::top(), toSQLTCHAR(), QString::toUcs4(), QStringRef::toUcs4(), QApplicationPrivate::translateTouchEvent(), and WinMain().

152 { detach(); return p->array; }
void detach()
Definition: qvector.h:147
Data * p
Definition: qvector.h:113

◆ data() [2/2]

template<typename T>
const T * QVector< T >::data ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 153 of file qvector.h.

153 { return p->array; }
Data * p
Definition: qvector.h:113

◆ detach()

template<typename T>
void QVector< T >::detach ( )
inline
Warning
This function is not part of the public interface.

Definition at line 147 of file qvector.h.

Referenced by QGLCmap::detach(), and QStack< State >::top().

147 { if (d->ref != 1) detach_helper(); }
QBasicAtomicInt ref
Definition: qvector.h:68
QVectorData * d
Definition: qvector.h:109
void detach_helper()
Definition: qvector.h:336

◆ detach_helper()

template<typename T >
void QVector< T >::detach_helper ( )
private

Definition at line 336 of file qvector.h.

337 { realloc(d->size, d->alloc); }
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
int size
Definition: qvector.h:70
void realloc(int size, int alloc)
Definition: qvector.h:472

◆ empty()

template<typename T>
bool QVector< T >::empty ( ) const
inline

This function is provided for STL compatibility.

It is equivalent to isEmpty(), returning true if the vector is empty; otherwise returns false.

Definition at line 285 of file qvector.h.

Referenced by QSplitterPrivate::doResize(), QDockAreaLayout::getGrid(), QDirModelPrivate::invalidate(), QToolBarLayout::layoutActions(), QTabBarPrivate::layoutTabs(), QRBTree< int >::order(), qGeomCalc(), QBoxLayoutPrivate::setupGeom(), QFormLayoutPrivate::setupVerticalLayoutData(), and QPdfEnginePrivate::writePage().

286  { return d->size == 0; }
QVectorData * d
Definition: qvector.h:109
int size
Definition: qvector.h:70

◆ end() [1/2]

template<typename T>
QVector::iterator QVector< T >::end ( )
inline

Returns an STL-style iterator pointing to the imaginary item after the last item in the vector.

See also
begin(), constEnd()

Definition at line 250 of file qvector.h.

Referenced by QFileSystemModelPrivate::_q_fileSystemChanged(), QWizardPrivate::_q_handleFieldObjectDestroyed(), QSortFilterProxyModelPrivate::_q_sourceDataChanged(), QDBusAdaptorConnector::addAdaptor(), QRegExpEngine::addPlusTransitions(), QXcbWindowSurface::beginPaint(), QXlibWindowSurface::beginPaint(), QX11WindowSurface::beginPaint(), QRasterWindowSurface::beginPaint(), QWSMemorySurface::beginPaint(), QListViewPrivate::closestIndex(), QPathClipper::doClip(), QTextDocumentLayoutPrivate::drawFlow(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QPatternist::TemplateMode::finalize(), QTextDocumentLayoutPrivate::frameIteratorForYPosition(), QPathClipper::handleCrossingEdges(), huntAndDestroy(), QIconModeViewBase::itemsRect(), QTextDocumentLayoutPrivate::layoutFlow(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items(), qDBusPropertySet(), qtKey2CocoaKey(), QDBusConnection::registerObject(), QListViewPrivate::removeCurrentAndDisabled(), QSortFilterProxyModel::removeRows(), QListViewPrivate::selection(), QTableModel::setItem(), QVariantAnimationPrivate::setValueAt(), QTableModel::sort(), QSortFilterProxyModelPrivate::sort_source_rows(), QStandardItemPrivate::sortChildren(), splitPolygon(), QDBusConnection::unregisterObject(), QSortFilterProxyModelPrivate::updateChildrenMapping(), and QVariantAnimationPrivate::valueAt().

250 { detach(); return p->array + d->size; }
void detach()
Definition: qvector.h:147
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70

◆ end() [2/2]

template<typename T>
QVector::const_iterator QVector< T >::end ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 251 of file qvector.h.

251 { return p->array + d->size; }
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70

◆ endsWith()

template<typename T>
bool QVector< T >::endsWith ( const T &  value) const
inline

Returns true if this vector is not empty and its last item is equal to value; otherwise returns false.

Since
4.5
See also
isEmpty(), last()

Definition at line 265 of file qvector.h.

265 { return !isEmpty() && last() == t; }
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ erase() [1/2]

template<typename T >
Q_TYPENAME QVector< T >::iterator QVector< T >::erase ( iterator  begin,
iterator  end 
)

Removes all the items from begin up to (but not including) end.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns an iterator to the same item that end referred to before the call.

Definition at line 627 of file qvector.h.

Referenced by QWizardPrivate::_q_handleFieldObjectDestroyed(), QSortFilterProxyModelPrivate::_q_sourceDataChanged(), QListViewPrivate::removeCurrentAndDisabled(), QVariantAnimationPrivate::setValueAt(), and QSortFilterProxyModelPrivate::updateChildrenMapping().

628 {
629  int f = int(abegin - p->array);
630  int l = int(aend - p->array);
631  int n = l - f;
632  detach();
634  qCopy(p->array+l, p->array+d->size, p->array+f);
635  T *i = p->array+d->size;
636  T* b = p->array+d->size-n;
637  while (i != b) {
638  --i;
639  i->~T();
640  }
641  } else {
642  memmove(p->array + f, p->array + l, (d->size-l)*sizeof(T));
643  }
644  d->size -= n;
645  return p->array + f;
646 }
void detach()
Definition: qvector.h:147
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
QFactoryLoader * l
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
Definition: qalgorithms.h:79

◆ erase() [2/2]

template<typename T>
QVector::iterator QVector< T >::erase ( iterator  pos)
inline

Removes the item pointed to by the iterator pos from the vector, and returns an iterator to the next item in the vector (which may be end()).

See also
insert(), remove()

Definition at line 256 of file qvector.h.

Referenced by QVector< QPoint >::erase().

256 { return erase(pos, pos+1); }
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Definition: qvector.h:627

◆ fill()

template<typename T>
QVector< T > & QVector< T >::fill ( const T &  value,
int  size = -1 
)

Assigns value to all items in the vector.

If size is different from -1 (the default), the vector is resized to size size beforehand.

Example:

QVector<QString> vector(3);
vector.fill("Yes");
// vector: ["Yes", "Yes", "Yes"]
vector.fill("oh", 5);
// vector: ["oh", "oh", "oh", "oh", "oh"]
See also
resize()

Definition at line 665 of file qvector.h.

Referenced by QRegExpCharClass::addCategories(), QRegExpCharClass::addRange(), QRegExpEngine::Box::Box(), QSortFilterProxyModelPrivate::build_source_to_proxy_mapping(), QTextHtmlExporter::emitTable(), QDB2Result::exec(), QGLEngineShaderManager::getUniformLocation(), QGraphicsSceneBspTree::initialize(), QTextDocumentLayoutPrivate::layoutTable(), QDB2Result::nextResult(), QRegExpCharClass::QRegExpCharClass(), qt_token_info::qt_token_info(), QSyntaxHighlighterPrivate::reformatBlock(), QDB2Result::reset(), QRegExpCharClass::setNegative(), QRegExpEngine::setup(), QRegExpEngine::Box::setupHeuristics(), and QMenuPrivate::updateActionRects().

666 {
667  const T copy(from);
668  resize(asize < 0 ? d->size : asize);
669  if (d->size) {
670  T *i = p->array + d->size;
671  T *b = p->array;
672  while (i != b)
673  *--i = copy;
674  }
675  return *this;
676 }
QVectorData * d
Definition: qvector.h:109
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ first() [1/2]

template<typename T>
T & QVector< T >::first ( )
inline

◆ first() [2/2]

template<typename T>
const T & QVector< T >::first ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 261 of file qvector.h.

261 { Q_ASSERT(!isEmpty()); return *begin(); }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ free()

template<typename T >
void QVector< T >::free ( Data d)
private

Definition at line 458 of file qvector.h.

459 {
461  T* b = x->array;
462  union { QVectorData *d; Data *p; } u;
463  u.p = x;
464  T* i = b + u.d->size;
465  while (i-- != b)
466  i->~T();
467  }
468  x->free(x, alignOfTypedData());
469 }
quint16 u
QVectorData * d
Definition: qvector.h:109
int alignOfTypedData() const
Definition: qvector.h:325
QVectorTypedData< T > Data
Definition: qvector.h:107
Data * p
Definition: qvector.h:113

◆ fromList()

template<typename T>
QVector< T > QVector< T >::fromList ( const QList< T > &  list)
static

Returns a QVector object with the data contained in list.

Example:

list << "Sven" << "Kim" << "Ola";
// vect: ["Sven", "Kim", "Ola"]
See also
toList(), QList::toVector()

Definition at line 789 of file qvector.h.

Referenced by QDBusPendingCallPrivate::setReplyCallback().

790 {
791  return list.toVector();
792 }
QVector< T > toVector() const
Returns a QVector object with the data contained in this QList.
Definition: qvector.h:780

◆ fromStdVector()

template<typename T>
QVector< T > QVector< T >::fromStdVector ( const std::vector< T > &  vector)
inlinestatic

Returns a QVector object with the data contained in vector.

The order of the elements in the QVector is the same as in vector.

Example:

std::vector<double> stdvector;
vector.push_back(1.2);
vector.push_back(0.5);
vector.push_back(3.14);
See also
toStdVector(), QList::fromStdList()

Definition at line 308 of file qvector.h.

309  { QVector<T> tmp; tmp.reserve(int(vector.size())); qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
Definition: qalgorithms.h:79
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339

◆ front() [1/2]

template<typename T>
T & QVector< T >::front ( )
inline

This function is provided for STL compatibility.

It is equivalent to first().

Definition at line 287 of file qvector.h.

Referenced by QSvgText::draw().

287 { return first(); }
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260

◆ front() [2/2]

template<typename T>
QVector::const_reference QVector< T >::front ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 288 of file qvector.h.

288 { return first(); }
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260

◆ indexOf()

template<typename T>
int QVector< T >::indexOf ( const T &  value,
int  from = 0 
) const

Returns the index position of the first occurrence of value in the vector, searching forward from index position from.

Returns -1 if no item matched.

Example:

vector << "A" << "B" << "C" << "B" << "A";
vector.indexOf("B"); // returns 1
vector.indexOf("B", 1); // returns 1
vector.indexOf("B", 2); // returns 3
vector.indexOf("X"); // returns -1

This function requires the value type to have an implementation of operator==().

See also
lastIndexOf(), contains()

Definition at line 698 of file qvector.h.

Referenced by QPdfEnginePrivate::addConstantAlphaObject(), QStandardItemPrivate::childIndex(), QGLColormap::find(), QTableModel::index(), QTableModel::itemChanged(), QStandardItemModelPrivate::itemChanged(), q_configFromQPlatformWindowFormat(), q_reduceConfigAttributes(), QBspTree::remove(), QGraphicsAnchorLayoutPrivate::removeAnchor(), QTableModel::removeItem(), QGraphicsScenePrivate::removeItemHelper(), QWindowsFileSystemWatcherEngine::removePaths(), ShaderEffect::removeRenderTarget(), and QWindowsFileSystemWatcherEngineThread::run().

699 {
700  if (from < 0)
701  from = qMax(from + d->size, 0);
702  if (from < d->size) {
703  T* n = p->array + from - 1;
704  T* e = p->array + d->size;
705  while (++n != e)
706  if (*n == t)
707  return n - p->array;
708  }
709  return -1;
710 }
QVectorData * d
Definition: qvector.h:109
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ insert() [1/4]

template<typename T>
void QVector< T >::insert ( int  i,
const T &  value 
)
inline

Inserts value at index position i in the vector.

If i is 0, the value is prepended to the vector. If i is size(), the value is appended to the vector.

Example:

vector << "alpha" << "beta" << "delta";
vector.insert(2, "gamma");
// vector: ["alpha", "beta", "gamma", "delta"]

For large vectors, this operation can be slow (linear time), because it requires moving all the items at indexes i and above by one position further in memory. If you want a container class that provides a fast insert() function, use QLinkedList instead.

See also
append(), prepend(), remove()

Definition at line 362 of file qvector.h.

Referenced by QStandardItemModelPrivate::columnsInserted(), convert_indexed8_to_ARGB_PM_inplace(), convert_indexed8_to_RGB_inplace(), QTableModel::ensureSorted(), QNetworkAuthenticationCache::insert(), QSortFilterProxyModelPrivate::insert_source_items(), QTableModel::insertColumns(), QTextTable::insertColumns(), QTreeModel::insertColumns(), insertOrRemoveItems(), QTableModel::insertRows(), ShaderEffectItem::lookThroughShaderCode(), operator>>(), QDBusConnection::registerObject(), QStandardItemModelPrivate::rowsInserted(), QGradient::setColorAt(), QTableModel::setItem(), QVariantAnimationPrivate::setValueAt(), QSortFilterProxyModelPrivate::source_items_inserted(), and QTextEngine::splitItem().

363 { Q_ASSERT_X(i >= 0 && i <= d->size, "QVector<T>::insert", "index out of range");
364  insert(begin() + i, 1, t); }
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ insert() [2/4]

template<typename T>
void QVector< T >::insert ( int  i,
int  count,
const T &  value 
)
inline

Inserts count copies of value at index position i in the vector.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Example:

vector << 2.718 << 1.442 << 0.4342;
vector.insert(1, 3, 9.9);
// vector: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342]

Definition at line 366 of file qvector.h.

367 { Q_ASSERT_X(i >= 0 && i <= d->size, "QVector<T>::insert", "index out of range");
368  insert(begin() + i, n, t); }
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ insert() [3/4]

template<typename T>
Q_TYPENAME QVector< T >::iterator QVector< T >::insert ( iterator  before,
int  count,
const T &  value 
)

Inserts count copies of value in front of the item pointed to by the iterator before.

Returns an iterator pointing at the first of the inserted items.

Definition at line 593 of file qvector.h.

594 {
595  int offset = int(before - p->array);
596  if (n != 0) {
597  const T copy(t);
598  if (d->ref != 1 || d->size + n > d->alloc)
599  realloc(d->size, QVectorData::grow(sizeOfTypedData(), d->size + n, sizeof(T),
602  T *b = p->array + d->size;
603  T *i = p->array + d->size + n;
604  while (i != b)
605  new (--i) T;
606  i = p->array + d->size;
607  T *j = i + n;
608  b = p->array + offset;
609  while (i != b)
610  *--j = *--i;
611  i = b+n;
612  while (i != b)
613  *--i = copy;
614  } else {
615  T *b = p->array + offset;
616  T *i = b + n;
617  memmove(i, b, (d->size - offset) * sizeof(T));
618  while (i != b)
619  new (--i) T(copy);
620  }
621  d->size += n;
622  }
623  return p->array + offset;
624 }
QBasicAtomicInt ref
Definition: qvector.h:68
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
int sizeOfTypedData()
Definition: qvector.h:320
static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive)
Definition: qvector.cpp:85
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
void realloc(int size, int alloc)
Definition: qvector.h:472

◆ insert() [4/4]

template<typename T>
QVector::iterator QVector< T >::insert ( iterator  before,
const T &  value 
)
inline

Inserts value in front of the item pointed to by the iterator before.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns an iterator pointing at the inserted item.

Definition at line 254 of file qvector.h.

Referenced by QVector< QPoint >::insert().

254 { return insert(before, 1, x); }
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362

◆ isDetached()

template<typename T>
bool QVector< T >::isDetached ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 148 of file qvector.h.

148 { return d->ref == 1; }
QBasicAtomicInt ref
Definition: qvector.h:68
QVectorData * d
Definition: qvector.h:109

◆ isEmpty()

template<typename T>
bool QVector< T >::isEmpty ( ) const
inline

Returns true if the vector has size 0; otherwise returns false.

See also
size(), resize()

Definition at line 139 of file qvector.h.

Referenced by QGraphicsScenePrivate::_q_polishItems(), QSortFilterProxyModelPrivate::_q_sourceDataChanged(), QPainterPath::addPolygon(), QDirIteratorPrivate::advance(), QImage::allGray(), QProxyFontEngine::alphaMapForGlyph(), QTextDocumentPrivate::appendUndoItem(), QPaintBufferEngine::brushChanged(), QCss::StyleSheet::buildIndexes(), QScript::callQtMethod(), QSvgHandler::characters(), cleanupDeletedNodes(), QTextDocumentPrivate::clearUndoRedoStacks(), QTreeWidgetItem::clone(), QTextHtmlImporter::closeTag(), convert_indexed8_to_RGB16_inplace(), convert_RGB_to_Indexed8(), QPainterPathStroker::createStroke(), QSvgHandler::currentColor(), QPatternist::AccelTreeBuilder< true >::currentParent(), QPen::dashPattern(), QGraphicsSceneBspTree::debug(), QTextDocumentLayoutPrivate::drawFlow(), QGraphicsScenePrivate::drawItemHelper(), QTextHtmlExporter::emitTable(), QSvgHandler::endElement(), QCoreApplication::exec(), QOCICols::execBatch(), QWinSettingsPrivate::fileName(), findObject(), QWidgetBackingStore::flush(), QTextEngine::format(), QTextEngine::formatIndex(), QTextDocumentLayoutPrivate::frameIteratorForYPosition(), QWindowsAccessible::get_accSelection(), QXlibWindow::getNetWmState(), getNetWmState(), QGLEngineShaderManager::getUniformLocation(), QSortFilterProxyModelPrivate::handle_filter_changed(), QPathClipper::handleCrossingEdges(), QDirIterator::hasNext(), QCoreApplication::hasPendingEvents(), QStyleSheetStyle::hasStyleRule(), QSpanData::initTexture(), QTreeWidgetItem::insertChild(), QTreeWidgetItem::insertChildren(), QTextTable::insertColumns(), QTreeModel::insertColumns(), QPaintBuffer::isEmpty(), QDeclarativeBindingCompiler::isValid(), QTreeView::keyPressEvent(), QTextDocumentLayoutPrivate::layoutFlow(), Document::load(), QHeaderViewPrivate::logicalIndex(), QWidgetBackingStore::markDirty(), QStandardItemModel::mimeData(), miSetExtents(), QListView::moveCursor(), QPatternist::PullBridge::next(), StringSplitter::next(), QPatternist::XQueryTokenizer::nextToken(), QXmlSimpleReaderPrivate::parseAttlistDecl(), QXmlSimpleReaderPrivate::parseAttribute(), QXmlSimpleReaderPrivate::parseAttType(), QXmlSimpleReaderPrivate::parseAttValue(), QXmlSimpleReaderPrivate::parseBeginOrContinue(), QXmlSimpleReaderPrivate::parseChoiceSeq(), QXmlSimpleReaderPrivate::parseComment(), QXmlSimpleReaderPrivate::parseContent(), QXmlSimpleReaderPrivate::parseDoctype(), QXmlSimpleReaderPrivate::parseElement(), QXmlSimpleReaderPrivate::parseElementDecl(), QXmlSimpleReaderPrivate::parseEntityDecl(), QXmlSimpleReaderPrivate::parseEntityValue(), QXmlSimpleReaderPrivate::parseExternalID(), QXmlSimpleReaderPrivate::parseMarkupdecl(), QXmlSimpleReaderPrivate::parseMisc(), QXmlSimpleReaderPrivate::parseName(), QXmlSimpleReaderPrivate::parseNmtoken(), QXmlSimpleReaderPrivate::parseNotationDecl(), QXmlSimpleReaderPrivate::parsePEReference(), QXmlSimpleReaderPrivate::parsePI(), QXmlSimpleReaderPrivate::parseProlog(), QXmlSimpleReaderPrivate::parseReference(), QXmlSimpleReaderPrivate::parseString(), QPaintBufferEngine::penChanged(), QListModeViewBase::perItemScrollingPageSteps(), QPixmapIconEngine::pixmap(), QStack< State >::pop(), QPatternist::XQueryTokenizer::popState(), QTreeWidgetItemPrivate::propagateDisabled(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add(), qCreateParamString(), qDrawPlainRect(), qLess< Item::List >::qLess(), qstring_to_xtp(), QPatternist::XSLTTokenizer::queueOnExit(), QWinSettingsPrivate::QWinSettingsPrivate(), QDBusConnection::registerObject(), QTextEngine::resolveAdditionalFormats(), QFileInfoGatherer::run(), QTreeViewPrivate::select(), QPatternist::AccelTree::sendNamespaces(), QAbstractXmlNodeModel::sendNamespaces(), QPen::setDashPattern(), QTreeWidgetItem::setFlags(), QStandardItemPrivate::setModel(), QWidgetPrivate::setNetWmWindowTypes(), QPdf::Stroker::setPen(), QListView::setSelection(), QCosmeticStroker::setup(), QXlibWindow::setWindowFlags(), QComboBox::showPopup(), QGraphicsAnchorLayoutPrivate::simplifyGraph(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QGraphicsAnchorLayoutPrivate::simplifyVertices(), QPatternist::SortTuple::SortTuple(), QSvgHandler::startElement(), QGradient::stops(), QPatternist::AccelTreeResourceLoader::streamToReceiver(), QTreeWidgetItem::takeChild(), QTreeWidgetItem::takeChildren(), QStack< State >::top(), QPaintBufferEngine::transformChanged(), QHeaderViewPrivate::visualIndex(), QFontSubset::widthArray(), and QWinSettingsPrivate::writeHandle().

139 { return d->size == 0; }
QVectorData * d
Definition: qvector.h:109
int size
Definition: qvector.h:70

◆ isSharedWith()

template<typename T>
bool QVector< T >::isSharedWith ( const QVector< T > &  other) const
inline
Warning
This function is not part of the public interface.

Definition at line 150 of file qvector.h.

150 { return d == other.d; }
QVectorData * d
Definition: qvector.h:109

◆ last() [1/2]

template<typename T>
T & QVector< T >::last ( )
inline

Returns a reference to the last item in the vector.

This function assumes that the vector isn't empty.

See also
first(), isEmpty()

Definition at line 262 of file qvector.h.

Referenced by QPaintBufferEngine::brushChanged(), createSequence(), QListModeViewBase::dragMoveEvent(), QTextDocumentLayoutPrivate::drawFlow(), QListModeViewBase::dropOn(), QTextEngine::endOfLine(), QTextDocumentLayoutPrivate::layoutFlow(), QTextDocumentLayoutPrivate::layoutTable(), QPaintBufferEngine::penChanged(), QListModeViewBase::perItemScrollingPageSteps(), QTextHtmlImporter::processBlockNode(), QTest::qExec(), SequentialAnchorData::SequentialAnchorData(), QListView::setSelection(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QPaintBufferEngine::transformChanged(), QPdfEnginePrivate::writePage(), and QPdfEnginePrivate::writeTail().

262 { Q_ASSERT(!isEmpty()); return *(end()-1); }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ last() [2/2]

template<typename T>
const T & QVector< T >::last ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 263 of file qvector.h.

263 { Q_ASSERT(!isEmpty()); return *(end()-1); }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ lastIndexOf()

template<typename T>
int QVector< T >::lastIndexOf ( const T &  value,
int  from = -1 
) const

Returns the index position of the last occurrence of the value value in the vector, searching backward from index position from.

If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.

Example:

vector << "A" << "B" << "C" << "B" << "A";
vector.lastIndexOf("B"); // returns 3
vector.lastIndexOf("B", 3); // returns 3
vector.lastIndexOf("B", 2); // returns 1
vector.lastIndexOf("X"); // returns -1

This function requires the value type to have an implementation of operator==().

See also
indexOf()

Definition at line 713 of file qvector.h.

Referenced by QStandardItemPrivate::childIndex().

714 {
715  if (from < 0)
716  from += d->size;
717  else if (from >= d->size)
718  from = d->size-1;
719  if (from >= 0) {
720  T* b = p->array;
721  T* n = p->array + from + 1;
722  while (n != b) {
723  if (*--n == t)
724  return n - b;
725  }
726  }
727  return -1;
728 }
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70

◆ malloc()

template<typename T >
QVectorData * QVector< T >::malloc ( int  alloc)
inlineprivate

Definition at line 403 of file qvector.h.

404 {
405  QVectorData *vectordata = QVectorData::allocate(sizeOfTypedData() + (aalloc - 1) * sizeof(T), alignOfTypedData());
406  Q_CHECK_PTR(vectordata);
407  return vectordata;
408 }
static QVectorData * allocate(int size, int alignment)
Definition: qvector.cpp:65
int alignOfTypedData() const
Definition: qvector.h:325
int sizeOfTypedData()
Definition: qvector.h:320
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853

◆ mid()

template<typename T >
Q_OUTOFLINE_TEMPLATE QVector< T > QVector< T >::mid ( int  pos,
int  length = -1 
) const

Returns a vector whose elements are copied from this vector, starting at position pos.

If length is -1 (the default), all elements after pos are copied; otherwise length elements (or all remaining elements if there are less than length elements) are copied.

Definition at line 754 of file qvector.h.

755 {
756  if (length < 0)
757  length = size() - pos;
758  if (pos == 0 && length == size())
759  return *this;
760  if (pos + length > size())
761  length = size() - pos;
762  QVector<T> copy;
763  copy.reserve(length);
764  for (int i = pos; i < pos + length; ++i)
765  copy += at(i);
766  return copy;
767 }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator!=()

template<typename T>
bool QVector< T >::operator!= ( const QVector< T > &  other) const
inline

Returns true if other is not equal to this vector; otherwise returns false.

Two vectors are considered equal if they contain the same values in the same order.

This function requires the value type to have an implementation of operator==().

See also
operator==()

Definition at line 135 of file qvector.h.

135 { return !(*this == v); }

◆ operator+()

template<typename T>
QVector< T > QVector< T >::operator+ ( const QVector< T > &  other) const
inline

Returns a vector that contains all the items in this vector followed by all the items in the other vector.

See also
operator+=()

Definition at line 294 of file qvector.h.

295  { QVector n = *this; n += l; return n; }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QFactoryLoader * l

◆ operator+=() [1/2]

template<typename T>
QVector< T > & QVector< T >::operator+= ( const QVector< T > &  other)

Appends the items of the other vector to this vector and returns a reference to this vector.

See also
operator+(), append()

Definition at line 679 of file qvector.h.

680 {
681  int newSize = d->size + l.d->size;
682  realloc(d->size, newSize);
683 
684  T *w = p->array + newSize;
685  T *i = l.p->array + l.d->size;
686  T *b = l.p->array;
687  while (i != b) {
689  new (--w) T(*--i);
690  else
691  *--w = *--i;
692  }
693  d->size = newSize;
694  return *this;
695 }
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70
void realloc(int size, int alloc)
Definition: qvector.h:472
QFactoryLoader * l

◆ operator+=() [2/2]

template<typename T>
void QVector< T >::operator+= ( const T &  value)
inline

Appends value to the vector.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
append(), operator<<()

Definition at line 296 of file qvector.h.

297  { append(t); return *this; }
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573

◆ operator<<() [1/2]

template<typename T>
QVector< T > & QVector< T >::operator<< ( const T &  value)
inline

Appends value to the vector and returns a reference to this vector.

See also
append(), operator+=()

Definition at line 298 of file qvector.h.

299  { append(t); return *this; }
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573

◆ operator<<() [2/2]

template<typename T>
QVector< T > & QVector< T >::operator<< ( const QVector< T > &  l)
inline

Appends other to the vector and returns a reference to the vector.

Definition at line 300 of file qvector.h.

301  { *this += l; return *this; }
QFactoryLoader * l

◆ operator=()

template<typename T>
QVector< T > & QVector< T >::operator= ( const QVector< T > &  v)

Assigns other to this vector and returns a reference to this vector.

Definition at line 390 of file qvector.h.

391 {
392  QVectorData *o = v.d;
393  o->ref.ref();
394  if (!d->ref.deref())
395  free(p);
396  d = o;
397  if (!d->sharable)
398  detach_helper();
399  return *this;
400 }
QBasicAtomicInt ref
Definition: qvector.h:68
uint sharable
Definition: qvector.h:77
QVectorData * d
Definition: qvector.h:109
void free(Data *d)
Definition: qvector.h:458
Data * p
Definition: qvector.h:113
void detach_helper()
Definition: qvector.h:336

◆ operator==()

template<typename T>
bool QVector< T >::operator== ( const QVector< T > &  other) const

Returns true if other is equal to this vector; otherwise returns false.

Two vectors are considered equal if they contain the same values in the same order.

This function requires the value type to have an implementation of operator==().

See also
operator!=()

Definition at line 649 of file qvector.h.

650 {
651  if (d->size != v.d->size)
652  return false;
653  if (d == v.d)
654  return true;
655  T* b = p->array;
656  T* i = b + d->size;
657  T* j = v.p->array + d->size;
658  while (i != b)
659  if (!(*--i == *--j))
660  return false;
661  return true;
662 }
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70

◆ operator[]() [1/2]

template<typename T >
T & QVector< T >::operator[] ( int  i)
inline

Returns the item at index position i as a modifiable reference.

i must be a valid index position in the vector (i.e., 0 <= i < size()).

Note that using non-const operators can cause QVector to do a deep copy.

See also
at(), value()

Definition at line 358 of file qvector.h.

Referenced by QObjectConnectionListVector::operator[]().

359 { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::operator[]", "index out of range");
360  return data()[i]; }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator[]() [2/2]

template<typename T >
const T & QVector< T >::operator[] ( int  i) const
inline

Same as at(i).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 354 of file qvector.h.

355 { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::operator[]", "index out of range");
356  return p->array[i]; }
Data * p
Definition: qvector.h:113
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ pop_back()

template<typename T>
void QVector< T >::pop_back ( )
inline

This function is provided for STL compatibility.

It is equivalent to erase(end() - 1).

Definition at line 283 of file qvector.h.

Referenced by QXmlSimpleReaderPrivate::next(), QRBTree< int >::order(), QXmlSimpleReaderPrivate::processElementEmptyTag(), and QXmlSimpleReaderPrivate::reportEndEntities().

283 { Q_ASSERT(!isEmpty()); erase(end()-1); }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Definition: qvector.h:627
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ pop_front()

template<typename T>
void QVector< T >::pop_front ( )
inline

This function is provided for STL compatibility.

It is equivalent to erase(begin()).

Definition at line 284 of file qvector.h.

Referenced by QFileInfoGatherer::run().

284 { Q_ASSERT(!isEmpty()); erase(begin()); }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Definition: qvector.h:627
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ prepend()

template<typename T>
void QVector< T >::prepend ( const T &  value)
inline

Inserts value at the beginning of the vector.

Example:

vector.prepend("one");
vector.prepend("two");
vector.prepend("three");
// vector: ["three", "two", "one"]

This is the same as vector.insert(0, value).

For large vectors, this operation can be slow (linear time), because it requires moving all the items in the vector by one position further in memory. If you want a container class that provides a fast prepend() function, use QList or QLinkedList instead.

See also
append(), insert()

Definition at line 378 of file qvector.h.

Referenced by QScript::callQtMethod(), QPatternist::XQueryTokenizer::nextToken(), QRegionPrivate::prepend(), and qt_watch_adopted_thread().

379 { insert(begin(), 1, t); }
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247

◆ push_back()

template<typename T>
void QVector< T >::push_back ( const T &  value)
inline

This function is provided for STL compatibility.

It is equivalent to append(value).

Definition at line 281 of file qvector.h.

Referenced by QTriangulator< T >::MonotoneToTriangles::decompose(), QSvgText::draw(), QSortFilterProxyModelPrivate::filter_changed(), QTriangulator< T >::initialize(), QTextEngine::insertionPointsForLine(), and QRBTree< int >::order().

281 { append(t); }
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573

◆ push_front()

template<typename T>
void QVector< T >::push_front ( const T &  value)
inline

This function is provided for STL compatibility.

It is equivalent to prepend(value).

Definition at line 282 of file qvector.h.

282 { prepend(t); }
void prepend(const T &t)
Inserts value at the beginning of the vector.
Definition: qvector.h:378

◆ realloc()

template<typename T >
void QVector< T >::realloc ( int  size,
int  alloc 
)
private

Definition at line 472 of file qvector.h.

473 {
474  Q_ASSERT(asize <= aalloc);
475  T *pOld;
476  T *pNew;
477  union { QVectorData *d; Data *p; } x;
478  x.d = d;
479 
480  if (QTypeInfo<T>::isComplex && asize < d->size && d->ref == 1 ) {
481  // call the destructor on all objects that need to be
482  // destroyed when shrinking
483  pOld = p->array + d->size;
484  pNew = p->array + asize;
485  while (asize < d->size) {
486  (--pOld)->~T();
487  d->size--;
488  }
489  }
490 
491  if (aalloc != d->alloc || d->ref != 1) {
492  // (re)allocate memory
494  x.d = malloc(aalloc);
495  Q_CHECK_PTR(x.p);
496  x.d->size = 0;
497  } else if (d->ref != 1) {
498  x.d = malloc(aalloc);
499  Q_CHECK_PTR(x.p);
501  x.d->size = 0;
502  } else {
503  ::memcpy(x.p, p, sizeOfTypedData() + (qMin(aalloc, d->alloc) - 1) * sizeof(T));
504  x.d->size = d->size;
505  }
506  } else {
507  QT_TRY {
508  QVectorData *mem = QVectorData::reallocate(d, sizeOfTypedData() + (aalloc - 1) * sizeof(T),
509  sizeOfTypedData() + (d->alloc - 1) * sizeof(T), alignOfTypedData());
510  Q_CHECK_PTR(mem);
511  x.d = d = mem;
512  x.d->size = d->size;
513  } QT_CATCH (const std::bad_alloc &) {
514  if (aalloc > d->alloc) // ignore the error in case we are just shrinking.
515  QT_RETHROW;
516  }
517  }
518  x.d->ref = 1;
519  x.d->alloc = aalloc;
520  x.d->sharable = true;
521  x.d->capacity = d->capacity;
522  x.d->reserved = 0;
523  }
524 
526  QT_TRY {
527  pOld = p->array + x.d->size;
528  pNew = x.p->array + x.d->size;
529  // copy objects from the old array into the new array
530  const int toMove = qMin(asize, d->size);
531  while (x.d->size < toMove) {
532  new (pNew++) T(*pOld++);
533  x.d->size++;
534  }
535  // construct all new objects when growing
536  while (x.d->size < asize) {
537  new (pNew++) T;
538  x.d->size++;
539  }
540  } QT_CATCH (...) {
541  free(x.p);
542  QT_RETHROW;
543  }
544 
545  } else if (asize > x.d->size) {
546  // initialize newly allocated memory to 0
547  qMemSet(x.p->array + x.d->size, 0, (asize - x.d->size) * sizeof(T));
548  }
549  x.d->size = asize;
550 
551  if (d != x.d) {
552  if (!d->ref.deref())
553  free(p);
554  d = x.d;
555  }
556 }
QBasicAtomicInt ref
Definition: qvector.h:68
static QVectorData * reallocate(QVectorData *old, int newsize, int oldsize, int alignment)
Definition: qvector.cpp:70
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int alignOfTypedData() const
Definition: qvector.h:325
void free(Data *d)
Definition: qvector.h:458
QVectorTypedData< T > Data
Definition: qvector.h:107
#define QT_RETHROW
Definition: qglobal.h:1539
int sizeOfTypedData()
Definition: qvector.h:320
Data * p
Definition: qvector.h:113
#define QT_CATCH(A)
Definition: qglobal.h:1537
int size
Definition: qvector.h:70
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
void * qMemSet(void *dest, int c, size_t n)
Definition: qglobal.cpp:2509
QVectorData * malloc(int alloc)
Definition: qvector.h:403
uint capacity
Definition: qvector.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define QT_TRY
Definition: qglobal.h:1536

◆ remove() [1/2]

template<typename T >
void QVector< T >::remove ( int  i)
inline

Removes the element at index position i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
insert(), replace(), fill()

Definition at line 374 of file qvector.h.

Referenced by QGraphicsScenePrivate::_q_polishItems(), QTextDocumentPrivate::clearUndoRedoStacks(), QStandardItemModelPrivate::columnsRemoved(), QWidgetBackingStore::dirtyOnScreenWidgetsRemoveAll(), QWidgetBackingStore::dirtyWidgetsRemoveAll(), QTableModel::ensureSorted(), QSortFilterProxyModelPrivate::filter_changed(), insertOrRemoveItems(), QPixmapIconEngine::pixmap(), q_reduceConfigAttributes(), qt_adopted_thread_watcher_function(), QBspTree::remove(), QSortFilterProxyModelPrivate::remove_proxy_interval(), QTableModel::removeColumns(), QTextTable::removeColumns(), QWindowsFileSystemWatcherEngine::removePaths(), ShaderEffect::removeRenderTarget(), QTableModel::removeRows(), QScript::QObjectConnectionManager::removeSignalHandler(), QHeaderViewPrivate::removeSpans(), QStandardItemModelPrivate::rowsRemoved(), QWindowsFileSystemWatcherEngineThread::run(), QTableModel::setItem(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), and QSortFilterProxyModelPrivate::source_items_removed().

375 { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::remove", "index out of range");
376  erase(begin() + i, begin() + i + 1); }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Definition: qvector.h:627
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ remove() [2/2]

template<typename T >
void QVector< T >::remove ( int  i,
int  count 
)
inline

Removes count elements from the middle of the vector, starting at index position i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
insert(), replace(), fill()

Definition at line 370 of file qvector.h.

371 { Q_ASSERT_X(i >= 0 && n >= 0 && i + n <= d->size, "QVector<T>::remove", "index out of range");
372  erase(begin() + i, begin() + i + n); }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
iterator erase(iterator begin, iterator end)
Removes all the items from begin up to (but not including) end.
Definition: qvector.h:627
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ replace()

template<typename T>
void QVector< T >::replace ( int  i,
const T &  value 
)
inline

Replaces the item at index position i with value.

i must be a valid index position in the vector (i.e., 0 <= i < size()).

See also
operator[](), remove()

Definition at line 382 of file qvector.h.

Referenced by QDesktopWidgetPrivate::init(), q_reduceConfigAttributes(), and QGLColormap::setEntry().

383 {
384  Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::replace", "index out of range");
385  const T copy(t);
386  data()[i] = copy;
387 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ reserve()

template<typename T >
void QVector< T >::reserve ( int  size)

Attempts to allocate memory for at least size elements.

If you know in advance how large the vector will be, you can call this function, and if you call resize() often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QVector will be a bit slower.

The sole purpose of this function is to provide a means of fine tuning QVector's memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the vector, call resize().

See also
squeeze(), capacity()

Definition at line 339 of file qvector.h.

Referenced by QWindowsMime::allFormatsForMime(), QAbstractItemModel::changePersistentIndexList(), QTableModel::columnItems(), QSortFilterProxyModelPrivate::create_mapping(), QPathClipper::doClip(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPainterPath::ensureData_helper(), QTableModel::ensureSorted(), flushRow(), QVector< QPoint >::fromStdVector(), QXmlStreamReaderPrivate::init(), QTreeWidgetItem::insertChild(), QTextDocumentLayoutPrivate::layoutFlow(), QTextDocumentLayoutPrivate::layoutTable(), QVector< QPoint >::mid(), QStandardItemModel::mimeData(), QPatternist::NamePool::NamePool(), operator>>(), QSvgHandler::parseCSStoXMLAttrs(), parseNumbersList(), QListModeViewBase::perItemScrollingPageSteps(), QListModeViewBase::perItemScrollToValue(), QDirIteratorPrivate::QDirIteratorPrivate(), qDrawShadePanel(), QTest::qExec(), QGraphicsViewPrivate::QGraphicsViewPrivate(), QTreeWidgetItem::QTreeWidgetItem(), QWindowsFileSystemWatcherEngineThread::QWindowsFileSystemWatcherEngineThread(), QXmlSerializerPrivate::QXmlSerializerPrivate(), QTextHtmlImporter::scanTable(), QTableModel::sort(), QStandardItemPrivate::sortChildren(), splitPolygon(), QCss::StyleSelector::styleRulesForNode(), QPolygonF::toPolygon(), QPainterPath::toSubpathPolygons(), QDeclarativePropertyCache::update(), and QConfFileSettingsPrivate::writeIniFile().

340 { if (asize > d->alloc) realloc(d->size, asize); if (d->ref == 1) d->capacity = 1; }
QBasicAtomicInt ref
Definition: qvector.h:68
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
int size
Definition: qvector.h:70
void realloc(int size, int alloc)
Definition: qvector.h:472
uint capacity
Definition: qvector.h:78

◆ resize()

template<typename T >
void QVector< T >::resize ( int  size)

Sets the size of the vector to size.

If size is greater than the current size, elements are added to the end; the new elements are initialized with a default-constructed value. If size is less than the current size, elements are removed from the end.

See also
size()

Definition at line 342 of file qvector.h.

Referenced by QObjectPrivate::addConnection(), addPoint(), QRegExpCharClass::addRange(), QPdfEnginePrivate::addXrefEntry(), QGraphicsViewPrivate::allocStyleOptionsArray(), QProxyFontEngine::alphaMapForGlyph(), QDeclarativePropertyCache::append(), QRegionPrivate::append(), QSqlCachedResult::cacheNext(), QStyleHelper::calcLines(), QTreeViewPrivate::calcLogicalIndices(), QScript::callQtMethod(), QRegExpCharClass::clear(), QTextDocumentPrivate::clearUndoRedoStacks(), QX11PaintEnginePrivate::clipPolygon_dev(), convert_indexed8_to_ARGB_PM_inplace(), convert_indexed8_to_RGB_inplace(), convert_Indexed8_to_X32(), convert_Mono_to_Indexed8(), convert_RGB_to_Indexed8(), convertWithPalette(), QImageData::create(), QBspTree::create(), QSortFilterProxyModelPrivate::create_mapping(), QShortcutMap::createNewSequences(), QPathClipper::doClip(), QWindowsStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QMotifStyle::drawPrimitive(), QTextHtmlExporter::emitTable(), enumCallback(), QPatternist::ReturnOrderBy::evaluateSingleton(), QDB2Result::exec(), QODBCResult::exec(), QSQLite2ResultPrivate::fetchNext(), QSQLiteResultPrivate::fetchNext(), find_trans_colors(), QWindowsAccessible::get_accSelection(), QDockAreaLayout::getGrid(), QXlibWindow::getNetWmState(), getNetWmState(), QFontSubset::getReverseMap(), QPatternist::GenericDynamicContext::globalItemCacheCell(), QPatternist::GenericDynamicContext::globalItemSequenceCacheCells(), QTextEngine::indexAdditionalFormats(), QDesktopWidgetPrivate::init(), QSqlCachedResultPrivate::init(), init_gray(), init_indexed(), QGraphicsSceneBspTree::initialize(), QHeaderViewPrivate::initializeIndexMapping(), QTableModel::insertColumns(), QTreeModel::insertColumns(), QTableModel::insertRows(), QTextDocumentLayoutPrivate::layoutFlow(), QTextDocumentLayoutPrivate::layoutTable(), QFontEngineMultiFT::loadEngine(), mergeInto(), miRegionOp(), QSqlCachedResultPrivate::nextIndex(), QDB2Result::nextResult(), QODBCResult::nextResult(), operator>>(), QXmlStreamReaderPrivate::parse(), PolygonRegion(), QTriangulator< T >::polyline(), QStack< State >::pop(), QRegionPrivate::prepend(), PtsToRegion(), Q_GLOBAL_STATIC_WITH_INITIALIZER(), qDrawPlainRect(), QImage::QImage(), qstring_to_xtp(), query_colormap(), qWinCmdLine(), QXmlSerializerPrivate::QXmlSerializerPrivate(), QInternal::registerCallback(), QStateMachinePrivate::registerSignalTransition(), QDB2Result::reset(), QODBCResult::reset(), QXmlStreamReaderPrivate::resolveDtd(), QXmlStreamReaderPrivate::resolvePublicNamespaces(), QXmlStreamReaderPrivate::resolveTag(), QTextHtmlImporter::scanTable(), QAccessibleListView::selection(), QAccessibleIconView::selection(), QAccessibleListBox::selection(), QRegExpEngine::Box::set(), QImage::setColorCount(), QTreeModel::setColumnCount(), QTreeWidgetItem::setData(), QWSCalibratedMouseHandler::setFilterSize(), QRegion::setRects(), QGridLayoutEngine::setRowAlignment(), QListModeViewBase::setRowCount(), QGridLayoutEngine::setRowSizeHint(), QGridLayoutEngine::setRowSpacing(), QGridLayoutEngine::setRowStretchFactor(), QRegExpEngine::setup(), QFormLayoutPrivate::setupHfwLayoutData(), QFormLayoutPrivate::setupVerticalLayoutData(), QObject::setUserData(), QGridLayoutEngine::sizeHint(), QSortFilterProxyModelPrivate::source_items_inserted(), QRegExpEngine::startAtom(), QPainterPath::toFillPolygons(), QFontSubset::toTruetype(), QString::toUcs4(), QStringRef::toUcs4(), QTriangulator< T >::triangulate(), QMenuPrivate::updateActionRects(), QDockAreaLayoutInfo::updateSeparatorWidgets(), QDockAreaLayout::updateSeparatorWidgets(), QRegionPrivate::vector(), QRegionPrivate::vectorize(), and QMYSQLResult::virtual_hook().

343 { realloc(asize, (asize > d->alloc || (!d->capacity && asize < d->size && asize < (d->alloc >> 1))) ?
345  : d->alloc); }
int alloc
Definition: qvector.h:69
QVectorData * d
Definition: qvector.h:109
int sizeOfTypedData()
Definition: qvector.h:320
static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive)
Definition: qvector.cpp:85
void realloc(int size, int alloc)
Definition: qvector.h:472
uint capacity
Definition: qvector.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ setSharable()

template<typename T>
void QVector< T >::setSharable ( bool  sharable)
inline
Warning
This function is not part of the public interface.

Definition at line 149 of file qvector.h.

149 { if (!sharable) detach(); d->sharable = sharable; }
void detach()
Definition: qvector.h:147
uint sharable
Definition: qvector.h:77
QVectorData * d
Definition: qvector.h:109

◆ size()

template<typename T>
int QVector< T >::size ( ) const
inline

Returns the number of items in the vector.

See also
isEmpty(), resize()

Definition at line 137 of file qvector.h.

Referenced by QRegExpEngine::Box::addAnchorsToEngine(), QRegExpEngine::addCatTransitions(), QXmlStreamReader::addExtraNamespaceDeclarations(), QPdfEnginePrivate::addImage(), QRegExpEngine::addLookahead(), QRegExpEngine::addPlusTransitions(), addPoint(), QPainterPath::addPolygon(), QRegExpCharClass::addRange(), QPainterPath::addRegion(), QPainterPath::addText(), QPdfEnginePrivate::addXrefEntry(), QRawFont::advancesForGlyphIndexes(), QGraphicsViewPrivate::allocStyleOptionsArray(), QRegExpEngine::anchorAlternation(), QRegionPrivate::append(), QTextDocumentPrivate::appendUndoItem(), QSvgStrokeStyle::apply(), QTextEngine::attributes(), QTextEngine::beginningOfLine(), ShaderEffectItem::bindGeometry(), QAhiScreen::blit(), QTransformedScreen::blit(), blit_template(), QTextEngine::boundingBox(), QSortFilterProxyModelPrivate::build_source_to_proxy_mapping(), QScript::callQtMethod(), QRegExpEngine::Box::cat(), QRegExpEngine::Box::catAnchor(), QTextTableData::cellPosition(), checkGrayscale(), QWinSettingsPrivate::children(), QTextDocumentPrivate::clearUndoRedoStacks(), QPaintEngineEx::clip(), QX11PaintEnginePrivate::clipPolygon_dev(), QPdfBaseEnginePrivate::closePrintDevice(), closestMatch(), QImage::colorCount(), QScreen::compose(), convert_indexed8_to_ARGB_PM_inplace(), convert_indexed8_to_RGB16_inplace(), convert_indexed8_to_RGB_inplace(), convert_Indexed8_to_X32(), convert_Mono_to_Indexed8(), convert_Mono_to_X32(), convert_RGB_to_Indexed8(), QBBWindow::copyBack(), QRegExpEngine::createState(), cubicTo_clipped(), QTextLine::cursorToX(), QDB2Result::data(), QTreeWidgetItem::data(), QGraphicsSceneBspTree::debug(), QAbstractItemModel::decodeData(), QDBusMetaType::demarshall(), QWidgetBackingStore::dirtyRegion(), QWidgetBackingStore::dirtyWidgetsRemoveAll(), dither_to_Mono(), QPathClipper::doClip(), QLinuxFbScreen::doRedraw(), QVNCScreen::doRedraw(), QSvgTinyDocument::draw(), QTextLayout::draw(), QSvgText::draw(), QPainter::drawChord(), QPainter::drawConvexPolygon(), QPaintEngine::drawEllipse(), QGraphicsScenePrivate::drawItemHelper(), QPainter::drawLines(), QX11PaintEngine::drawPath(), QBlitterPaintEngine::drawPixmap(), QPainter::drawPoints(), QPainter::drawPolygon(), QPainter::drawPolyline(), QWindowsMobileStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QPainter::drawRects(), QPainter::drawText(), QTreeView::drawTree(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QStandardItemModel::dropMimeData(), QRegExpCharClass::dump(), QRegExpEngine::dump(), QRegExpEngine::Box::dump(), QTextEngine::elidedText(), QTextEngine::endOfLine(), QPatternist::InScopePrefixesFN::evaluateSequence(), QScript::QObjectConnectionManager::execute(), QCoreApplication::exit(), QProxyScreen::exposeRegion(), QScreen::exposeRegion(), QGL2PaintEngineExPrivate::fill(), QImage::fill(), QVGCompositionHelper::fillBackground(), QX11PaintEnginePrivate::fillPath(), QRasterPaintEngine::fillPolygon(), QBlitterPaintEngine::fillRect(), QBlitterPaintEnginePrivate::fillRect(), QVGPaintEngine::fillRegion(), fillRegion(), QGL2PaintEngineExPrivate::fillStencilWithVertexArray(), QSortFilterProxyModelPrivate::filter_changed(), QTextEngine::findItem(), findRealWindow(), fix_color_table(), QDirectFBScreen::flipSurface(), QDirectFbWindowSurface::flush(), QXcbWindowSurface::flush(), QMacWindowSurface::flush(), QWidgetBackingStore::flush(), QGLWindowSurface::flush(), QRasterWindowSurface::flush(), QAlphaPaintEngine::flushAndInit(), QPSPrintEnginePrivate::flushPage(), flushRow(), QPaintBuffer::frameEndIndex(), QTextEngine::freeMemory(), QPdf::generateDashes(), QGL2GradientCache::generateGradientColorTable(), QGLGradientCache::generateGradientColorTable(), QWinSettingsPrivate::get(), QWindowsAccessible::get_accSelection(), QGL2GradientCache::getBuffer(), QGLGradientCache::getBuffer(), QGradientCache::getBuffer(), QDockAreaLayout::getGrid(), QXlibWindow::getNetWmState(), getNetWmState(), QPatternist::GenericDynamicContext::globalItemCacheCell(), QPatternist::GenericDynamicContext::globalItemSequenceCacheCells(), QSortFilterProxyModelPrivate::handle_filter_changed(), QPathClipper::handleCrossingEdges(), QPatternist::AccelTree::hasPrefix(), QTextHtmlImporter::import(), QRegExpCharClass::in(), QStaticTextPrivate::init(), QClipData::initialize(), QTriangulator< T >::initialize(), QTextDocumentPrivate::insert(), QSortFilterProxyModelPrivate::insert_source_items(), QTextDocumentPrivate::insertBlock(), QTextEngine::insertionPointsForLine(), QXmlSerializer::isBindingInScope(), QGLColormap::isEmpty(), QDB2Result::isNull(), QODBCResult::isNull(), QBrush::isOpaque(), QTextEngine::itemize(), QTextLine::layout_helper(), QToolBarLayout::layoutActions(), QTextDocumentLayoutPrivate::layoutFlow(), QTextDocumentLayoutPrivate::layoutTable(), QTextEngine::lineNumberForTextPosition(), QFontEngineMultiXLFD::loadEngine(), QFontEngineMultiFT::loadEngine(), QFontEngineMultiWin::loadEngine(), QFontEngineMultiQPA::loadEngine(), QFontEngineMultiQWS::loadEngine(), make_widget_eventUPP(), QMatrix::map(), QTransform::map(), QTransformedScreen::mapFromDevice(), mapProjective(), QTransformedScreen::mapToDevice(), QScript::QObjectConnectionManager::mark(), QDBusMetaType::marshall(), QRegExpMatchState::matchHere(), QTextFormat::merge(), mergeInto(), QRasterPixmapData::metric(), QVGPaintEnginePrivate::modifyMask(), QVNCCursor::move(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::move(), QPatternist::AccelTree::namespaceBindings(), QAbstractXmlNodeModel::namespaceForPrefix(), QXmlSimpleReaderPrivate::next(), QSqlCachedResultPrivate::nextIndex(), QImage::numColors(), OffsetRegion(), operator<<(), operator>>(), QScreen::paintBackground(), QBlittablePixmapData::paintEngine(), QTableView::paintEvent(), QMdiArea::paintEvent(), QXmlStreamReaderPrivate::parse(), parseAnimateTransformNode(), parsePen(), parseStopNode(), QPdf::patternForBrush(), QStack< State >::pop(), QTextEngine::positionAfterVisualMovement(), QRasterBuffer::prepare(), QRegExpMatchState::prepareForMatch(), QRegionPrivate::prepend(), QDashStroker::processCurrentSubpath(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add(), QSortFilterProxyModelPrivate::proxy_to_source(), PtsToRegion(), QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(), qGeomCalc(), qglx_getProcAddress(), QPolygonF::QPolygonF(), QRegion::QRegion(), qstring_to_xtp(), qt_adopted_thread_watcher_function(), qt_bitmapToRegion(), qt_mac_clip_cg(), qt_mac_desktopSize(), qt_mac_fill_background(), qt_regionToPath(), qt_transparent_pixel(), query_colormap(), QVectorPathConverter::QVectorPathData::QVectorPathData(), qVectorToSet(), qWinCmdLine(), QRasterPaintEnginePrivate::rasterizeLine_dashed(), QSettings::registerFormat(), QStateMachinePrivate::registerSignalTransition(), QMetaType::registerType(), QSortFilterProxyModelPrivate::remove_source_items(), QGraphicsSceneBspTree::removeItems(), QScript::QObjectConnectionManager::removeSignalHandler(), ShaderEffectItem::renderEffect(), resolveColor(), QPatternist::ReturnOrderBy::ReturnOrderBy(), QImage::rgbSwapped(), rot(), QSvgPaintEngine::saveGradientStops(), QTextHtmlImporter::scanTable(), QDirectFbWindowSurface::scroll(), QXcbWindowSurface::scroll(), QXlibWindowSurface::scroll(), QRasterWindowSurface::scroll(), QWSMemorySurface::scroll(), QGraphicsItem::scroll(), QWidgetPrivate::scroll_sys(), QWidgetPrivate::scrollRect(), send_targets_selection(), QAbstractXmlNodeModel::sendNamespaces(), QXlibClipboard::sendTargetsSelection(), separatorMoveHelper(), QVNCCursor::set(), QVGPaintEnginePrivate::setBrush(), QPainter::setClipRegion(), QImage::setColor(), QGradient::setColorAt(), QImage::setColorCount(), QImage::setColorTable(), QSvgStrokeStyle::setDashArray(), QPen::setDashPattern(), QPainterPathStroker::setDashPattern(), QWSRegionEvent::setData(), QWSEmbedEvent::setData(), PvrEglWindowSurface::setDirectRegion(), QGLColormap::setEntries(), QGlyphRun::setGlyphIndexes(), QTableModel::setHeaderData(), QPdf::Stroker::setPen(), QImage::setPixel(), QGlyphRun::setPositions(), QTextFormat::setProperty(), QGradient::setStops(), QCoreGraphicsPaintEnginePrivate::setStrokePen(), QCosmeticStroker::setup(), QVGPaintEnginePrivate::setupColorRamp(), QRegExpEngine::setupState(), QObject::setUserData(), QPainter::setViewTransformEnabled(), QXlibWindow::setWindowFlags(), QGLColormap::size(), QVertexIndexVector::size(), QAhiScreen::solidFill(), solidFill_template(), QSortFilterProxyModelPrivate::source_items_about_to_be_removed(), QSortFilterProxyModelPrivate::source_items_inserted(), QSortFilterProxyModelPrivate::source_items_removed(), QSortFilterProxyModelPrivate::source_to_proxy(), splitPolygon(), QRegExpEngine::startAtom(), QPatternist::AccelTreeResourceLoader::streamToReceiver(), QRasterPaintEngine::stroke(), QEglContext::swapBuffersRegion2NOK(), QWidgetBackingStore::sync(), QRegExpMatchState::testAnchor(), QPainter::testRenderHint(), QTextEngine::tightBoundingBox(), QPainterPath::toFillPolygons(), QX11PixmapData::toImage(), QStack< State >::top(), QPainterPath::toSubpathPolygons(), QImage::transformed(), QSvgNode::transformedBounds(), QPainterPath::translate(), QDBusMetaType::typeToSignature(), QTextDocumentPrivate::undoRedo(), QStateMachinePrivate::unregisterSignalTransition(), QOpenGLPaintEngine::updateClipRegion(), QOpenGLPaintEnginePrivate::updateDepthClip(), QRasterPaintEngine::updatePen(), QGraphicsViewPrivate::updateRegion(), QGraphicsView::updateScene(), QVGPaintEngine::updateScissor(), QDockAreaLayoutInfo::updateSeparatorWidgets(), QDockAreaLayout::updateSeparatorWidgets(), ShaderEffectItem::updateShaderProgram(), QPdfBaseEngine::updateState(), QRegionPrivate::vector(), QRegionPrivate::vectorize(), QPixmapIconEngine::virtual_hook(), QTextEngine::width(), QTiffHandler::write(), QPixmapIconEngine::write(), QXmlStreamWriter::writeAttributes(), QXmlStreamWriter::writeCurrentToken(), QPdfEnginePrivate::writePage(), QPdfEnginePrivate::writePageRoot(), QPdfEnginePrivate::writeTail(), QTextLine::xToCursor(), QPaintBufferPrivate::~QPaintBufferPrivate(), QPainterPrivate::~QPainterPrivate(), QPdfEnginePrivate::~QPdfEnginePrivate(), QSvgText::~QSvgText(), QWidgetBackingStore::~QWidgetBackingStore(), and QWinSettingsPrivate::~QWinSettingsPrivate().

137 { return d->size; }
QVectorData * d
Definition: qvector.h:109
int size
Definition: qvector.h:70

◆ sizeOfTypedData()

template<typename T>
int QVector< T >::sizeOfTypedData ( )
inlineprivate

Definition at line 320 of file qvector.h.

320  {
321  // this is more or less the same as sizeof(Data), except that it doesn't
322  // count the padding at the end
323  return reinterpret_cast<const char *>(&(reinterpret_cast<const Data *>(this))->array[1]) - reinterpret_cast<const char *>(this);
324  }
QVectorTypedData< T > Data
Definition: qvector.h:107

◆ squeeze()

template<typename T>
void QVector< T >::squeeze ( )
inline

Releases any memory not required to store the items.

The sole purpose of this function is to provide a means of fine tuning QVector's memory usage. In general, you will rarely ever need to call this function.

See also
reserve(), capacity()

Definition at line 145 of file qvector.h.

Referenced by QGraphicsScenePrivate::_q_polishItems().

145 { realloc(d->size, d->size); d->capacity = 0; }
QVectorData * d
Definition: qvector.h:109
int size
Definition: qvector.h:70
void realloc(int size, int alloc)
Definition: qvector.h:472
uint capacity
Definition: qvector.h:78

◆ startsWith()

template<typename T>
bool QVector< T >::startsWith ( const T &  value) const
inline

Returns true if this vector is not empty and its first item is equal to value; otherwise returns false.

Since
4.5
See also
isEmpty(), first()

Definition at line 264 of file qvector.h.

264 { return !isEmpty() && first() == t; }
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ swap()

template<typename T>
void QVector< T >::swap ( QVector< T > &  other)
inline

Swaps vector other with this vector.

Since
4.8

This operation is very fast and never fails.

Definition at line 130 of file qvector.h.

Referenced by QStack< State >::swap(), QPolygon::swap(), and QPolygonF::swap().

130 { qSwap(d, other.d); }
QVectorData * d
Definition: qvector.h:109
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

◆ toList()

template<typename T >
Q_OUTOFLINE_TEMPLATE QList< T > QVector< T >::toList ( ) const

Returns a QList object with the data contained in this QVector.

Example:

vect << "red" << "green" << "blue" << "black";
QList<QString> list = vect.toList();
// list: ["red", "green", "blue", "black"]
See also
fromList(), QList::fromVector()

Definition at line 770 of file qvector.h.

Referenced by QList< QPostEvent >::fromVector(), operator<<(), and QPatternist::ListIterator< QXmlNodeModelIndexIteratorPointer, QVector< QXmlNodeModelIndexIteratorPointer > >::toList().

771 {
772  QList<T> result;
773  result.reserve(size());
774  for (int i = 0; i < size(); ++i)
775  result.append(at(i));
776  return result;
777 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ toStdVector()

template<typename T>
std::vector< T > QVector< T >::toStdVector ( ) const
inline

Returns a std::vector object with the data contained in this QVector.

Example:

vector << 1.2 << 0.5 << 3.14;
std::vector<double> stdvector = vector.toStdVector();
See also
fromStdVector(), QList::toStdList()

Definition at line 310 of file qvector.h.

311  { std::vector<T> tmp; tmp.reserve(size()); qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
Definition: qalgorithms.h:79
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ value() [1/2]

template<typename T >
Q_OUTOFLINE_TEMPLATE T QVector< T >::value ( int  i) const

Returns the value at index position i in the vector.

If the index i is out of bounds, the function returns a default-constructed value. If you are certain that i is within bounds, you can use at() instead, which is slightly faster.

See also
at(), operator[]()

Definition at line 559 of file qvector.h.

Referenced by QGridLayoutRowData::calculateGeometries(), QRegExpEngine::dump(), QGridLayoutEngine::fillRowData(), QXmlStreamAttributes::hasAttribute(), QTableModel::horizontalHeaderItem(), QTableModel::item(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::outputGraph(), QXmlStreamAttributes::QXmlStreamAttributes(), QListWidgetItem::setData(), QTableWidgetItem::setData(), QTreeWidgetItem::setData(), QTableModel::takeItem(), and QTableModel::verticalHeaderItem().

560 {
561  if (i < 0 || i >= d->size) {
562  return T();
563  }
564  return p->array[i];
565 }
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70

◆ value() [2/2]

template<typename T>
Q_OUTOFLINE_TEMPLATE T QVector< T >::value ( int  i,
const T &  defaultValue 
) const

If the index i is out of bounds, the function returns defaultValue.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 567 of file qvector.h.

568 {
569  return ((i < 0 || i >= d->size) ? defaultValue : p->array[i]);
570 }
QVectorData * d
Definition: qvector.h:109
Data * p
Definition: qvector.h:113
int size
Definition: qvector.h:70

Friends and Related Functions

◆ operator<<()

template<typename T>
QDataStream & operator<< ( QDataStream out,
const QVector< T > &  vector 
)
related

Writes the vector vector to stream out.

This function requires the value type to implement operator<<().

See also
Format of the QDataStream operators

Definition at line 312 of file qdatastream.h.

313 {
314  s << quint32(v.size());
315  for (typename QVector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
316  s << *it;
317  return s;
318 }
#define it(className, varName)
unsigned int quint32
Definition: qglobal.h:938
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245

◆ operator>>()

template<typename T>
QDataStream & operator>> ( QDataStream in,
QVector< T > &  vector 
)
related

Reads a vector from stream in into vector.

This function requires the value type to implement operator>>().

See also
Format of the QDataStream operators

Definition at line 297 of file qdatastream.h.

298 {
299  v.clear();
300  quint32 c;
301  s >> c;
302  v.resize(c);
303  for(quint32 i = 0; i < c; ++i) {
304  T t;
305  s >> t;
306  v[i] = t;
307  }
308  return s;
309 }
unsigned char c[8]
Definition: qnumeric_p.h:62
unsigned int quint32
Definition: qglobal.h:938

◆ QRegion

template<typename T>
friend class QRegion
friend

Definition at line 314 of file qvector.h.

Properties

◆ @94

union { ... }

◆ d

template<typename T>
QVectorData* QVector< T >::d

◆ p

template<typename T>
Data* QVector< T >::p

Definition at line 113 of file qvector.h.

Referenced by QVector< QPoint >::operator+=(), and QVector< QPoint >::operator==().


The documentation for this class was generated from the following files: