#include#include int main() { QVector numbers = {1, 2, 3}; numbers.push_back(4); numbers.insert(2, 5); for(int i=0; i
This example shows how to create a QVector with initial values and add elements to the end and at a specific index using push_back and insert functions respectively.
Example 2:#includeThis example shows how to create a QVector holding strings and how to access the last element using last function which returns a reference to the element. Then, we modify the last element and iterate through all elements using a range-based for loop. Package Library: QtCore#include int main() { QVector fruits = {"Apple", "Banana", "Grapes"}; QString& lastFruit = fruits.last(); lastFruit = "Orange"; for(auto fruit : fruits) { qDebug() << fruit; } return 0; }