There is following code. It creates QGraphicsView object, sets a scene and then there is created a QGraphicsWebView object which is added to the scene:
QGraphicsWebView* graphicsWebView;
QGraphicsScene* graphicsScene;
QGraphicsView* graphicsView;
QMainWindow* mainWindow;
class Deleter : public QObject
{
Q_OBJECT
public slots:
void deleteWebView()
{
mainWindow->hide();
mainWindow->centralWidget()->setParent(0);
mainWindow->setCentralWidget(new QWidget());
delete graphicsView; // <-- crashes about 2 seconds after that
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
mainWindow = new QMainWindow;
graphicsView = new QGraphicsView;
graphicsScene = new QGraphicsScene(graphicsView);
graphicsView->setScene(graphicsScene);
graphicsWebView = new QGraphicsWebView;
graphicsWebView->setUrl(QUrl("http://www.google.com"));
graphicsView->scene()->addItem(graphicsWebView);
graphicsView->setViewport(new QGLWidget());
graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
mainWindow->setAttribute(Qt::WA_TranslucentBackground);
mainWindow->setCentralWidget(graphicsView);
mainWindow->show();
Deleter d;
QTimer::singleShot(10000, &d, SLOT(deleteWebView()));
return app.exec();
}
#include "main.moc"
10 seconds later there is invoked a slot which tries to delete QGraphicsView object. The problem is that when I try to delete graphicsView, the program crashes after about 2 seconds. The backtraces are garbage. Theoretically QGraphicsView object should remove its children and the child is QGraphicsScene object. The scene should remove its child which is QGraphicsWebView object.
How to correctly delete QGraphicsView object without crashing the process?
This is Qt 4.8