Qvector class is a template class that provides a dynamic array.
Qvector <T> It is a kind of common container class of QT. It stores each of its objects in contiguous memory and can use the index number to quickly access them. Qlist<t>, qlinkedlist<t>, and qvarlengtharray<t> also provide similar functionality, using the following methods:
L Qlist generally use the most, it can meet most of our needs. Operations like Prepend () and insert () are usually faster than qvector, because the Qlist stores its objects differently (algorithmic complexity). and its index-based API is easier to use than qlinkedlist 's iterator-based API . Finally, it has less code expansion when executing a program.
L qlinkedlist, when you need to use a real linked list that requires you to insert objects into the middle of a table at a constant time, you want to use an iterator instead of an index number to access the object, this time using Qlinkedlist !
L qvector, if you want to store your object in contiguous memory, your object is larger than the pointer, and you want to avoid inserting the object into the heap's head individually, use Qvector.
L Qvarlengtharray, if you want a low-level variable-sized container, Qvarlengtharray is enough, it has the advantage of being fast!
Here is an example of using Qvector to store integer values and qstring:
Qvector<int> Integervector;
Qvector<qstring> Stringvector;
Qvector a vector container that holds objects, usually using the initial size to create a vector container. For example, the following code constructs a qvector with 200 elements:
Qvector<qstring> vector (200);
If the vector container object created is not assigned an initial value, it is initialized with the default constructor of the class that uses the vector container. Both the base type and the pointer type are initialized to 0, and if you want to initialize the object with a different initial value, you can add another parameter when initializing:
Qvector<qstring> vector ("Pass");
You can also call the fill () function to fill the vector container at any time.
But when you want to show the exact string inside,
In QT development, Qstring is converted to char * type by TOASCII (). Data ().
Qbytearray qstring::toascii () const
Returns an 8-bit representation of the string as a qbytearray.
If A codec has been set using the Qtextcodec::setcodecforcstrings (), it is used to convert the Unicode to 8-bit char; Otherwise this function does the same as ToLatin1 ().
Note that, despite the name, this function does not necessarily return a us-ascii (ANSI x3.4-1986) string and its result May is us-ascii compatible.
If encoding is set using the Setcodecforcstrings function, Toascii converts Unicode to a 8-bit char type, otherwise it is the same as toLatin1.
Qvector<qstring> shows the conversion of elements in a dynamic array with QString and char *