ahaan...
I removed the item i did not want and delete the pointer which was pointing to it by the following code. And my program then worked fine.
//sqMap is the class used for creation of squares
sqMap square = new sqMap(width, height)
...
...
scene->removeItem(square);
delete square;
//sqMap is the class used for creation of squares
sqMap square = new sqMap(width, height)
...
...
scene->removeItem(square);
delete square;
To copy to clipboard, switch view to plain text mode
But now i need to delete multiple last drawn items. So what i did was that i made a vector of type *sqMap and then pushed the items i wanted to delete into it and then removed and deleted them one by one. But some/all of the items don't get removed from the screen. Following code was used
...
...
...
std::vector<sqMap *> sqrBasket;
...
...
...
for(int pos=0 ; pos<sqrBasket.size(); pos++)
{
scene->removeItem(sqrBasket[pos]);
delete sqrBasket[pos];
}
for(int j=0; j<=i; j++)
{
tempHeight = array[j] / tempWidth;
[B]square = new sqMap(tempWidth, tempHeight);[/B]
square->setPos(xLocation,yLocation);
int size4toolTip = int(array[j]) * sum / (width * height);
square->setToolTip(toolTip);
[B] sqrBasket.push_back(square);[/B]
scene->addItem(square);
...
...
...
...
...
...
std::vector<sqMap *> sqrBasket;
...
...
...
for(int pos=0 ; pos<sqrBasket.size(); pos++)
{
scene->removeItem(sqrBasket[pos]);
delete sqrBasket[pos];
}
for(int j=0; j<=i; j++)
{
tempHeight = array[j] / tempWidth;
[B]square = new sqMap(tempWidth, tempHeight);[/B]
square->setPos(xLocation,yLocation);
int size4toolTip = int(array[j]) * sum / (width * height);
QString toolTip = QString::number(size4toolTip,10);
square->setToolTip(toolTip);
[B] sqrBasket.push_back(square);[/B]
scene->addItem(square);
...
...
...
To copy to clipboard, switch view to plain text mode
Does the proedure of removing mulitple items that i have followed is right?
Bookmarks