我有一个QGraphicsScene,里面有一个QPushButton,但是清除这个场景会导致我的应用程序崩溃。是否有正确的方法可以清除包含QWidget的场景?
当单击按钮时,以下代码会导致崩溃:
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <QPushButton>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsView *view = new QGraphicsView();
view->setScene(scene);
view->show();
QPushButton *button = new QPushButton("button");
QObject::connect(button, SIGNAL(clicked()), scene, SLOT(clear()));
QGraphicsProxyWidget *proxy = scene->addWidget(button);
return app.exec();
}