I have two classes: point
and mainwindow
.
I declared pointer of point class in mainwindow.h as:
point *item;
I create an object of point class in mainwindow.cpp:
void MainWindow::drawPoint(){
item = new point;
scene->addItem(item);
}
This function enables painting of point in qgraphicsscene
.
There is a vector that stores QPointF
values in point class. The storage class is the type of vector.
QVector<storage> point_vector;
set_point()
is defined in storage class that sets the value of point p1.
storage store_point;
store_point.set_point(p1);
point_vector.push_back(store_point);
On iterating the vector in mainwindow.cpp,
for(it = item->point_vector.begin(); it != item->point_vector.end(); it++)
{
qDebug() << "size" << item->point_vector.size() << "\n";
}
Even though I create multiple points in the scene, the size of vector always remains 1.
I think this might be happening because every time the function drawPoint()
is called, the previous object of point class is over-ridden.
I am unable to figure out how to resolve this issue. Any help will be appreciated.
Relevant Code