![]() ![]() QVector's value type must be an assignable data type. Note that using non-const operators and functions can cause QVector to do a deep copy of the data. You can also call capacity() to find out how much memory QVector actually allocated. 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. QVector tries to reduce the number of reallocations by preallocating up to twice as much memory as the actual data needs. If the new size is larger than the old size, QVector might need to reallocate the whole vector. Unlike plain C++ arrays, QVectors can be resized at any time by calling resize(). If you want a container class that provides fast insertion/removal in the middle, use QList or QLinkedList instead. 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. QVector provides these basic functions to add, move, and remove items: insert(), replace(), remove(), prepend(), append(). If you want to find out how many times a particular value occurs in the vector, use count(). ![]() If you simply want to check whether a vector contains a particular value, use contains().
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |