I cannot find a way to get the item lists from a QGraphicsScene. When trying the items() method, the program always crashes with a segfault.
Here is the bit of code where the problem occurs:
void MainWindow::updateMapView() {
scene
->addRect
(QRectF(0,
0,
10,
10), scenePen, sceneBrush
);
QList<QGraphicsItem*> items = scene->items();
for (int i = 0; i < items.size(); i++) {
scene->addItem(items[i]);
}
ui.map_view->setScene(scene);
}
void MainWindow::updateMapView() {
scene->addRect(QRectF(0, 0, 10, 10), scenePen, sceneBrush);
QList<QGraphicsItem*> items = scene->items();
for (int i = 0; i < items.size(); i++) {
scene->addItem(items[i]);
}
ui.map_view->setScene(scene);
}
To copy to clipboard, switch view to plain text mode
If I remove the middle four lines (and just add the QRectF and set the scene), the code runs fine and the rectangle is displayed. Once I try and get the items, I get the fault.
Any hints? I'm at a bit of a loss. Thanks.
Edit: This also occurs for some other functions too, including QGraphicsScene::width() and height(). Not addItem(), or any of the other add functions though.
Bookmarks