#include#include int main() { QVector nums; nums.append(1); nums.append(2); nums.append(3); // Adding an element to the front of the QVector nums.front() = 0; // Printing out the contents of the QVector qDebug() << nums; return 0; }
#includeIn this example, we create a QVector `nums` and append three integer values to it. We then use `constFront()` to access the first element of the QVector without modifying it. Finally, we print out the value of the first element. This can be useful when working with large data sets, as it avoids the overhead of copying the first element. Package library: Qt Core.#include int main() { QVector nums; nums.append(1); nums.append(2); nums.append(3); // Accessing the first element of the QVector const int& firstNum = nums.constFront(); // Printing out the value of the first element qDebug() << "The first number is" << firstNum; return 0; }