#includeint main() { // Creating a QVector of integers QVector nums = {1, 2, 3, 4}; // Adding elements to the QVector nums.append(5); nums.push_back(6); // Accessing elements of the QVector int first = nums.at(0); int last = nums.back(); return 0; }
class Point { public: Point(int x, int y) : m_x(x), m_y(y) {} int getX() const { return m_x; } int getY() const { return m_y; } private: int m_x; int m_y; }; int main() { // Creating a QVector of Point objects QVectorIn this example, we define a Point class with x and y coordinates and use QVector to store instances of that class. We also access the first and last elements of the QVector using the at() and back() methods.points = {Point(0, 0), Point(1, 1), Point(2, 3)}; // Accessing elements of the QVector Point first = points.at(0); Point last = points.back(); return 0; }