diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 48242462a..d1dbc6b18 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -101,7 +101,6 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : } connect(m_diagram, SIGNAL(showDiagram(Diagram*)), this, SIGNAL(showDiagram(Diagram*))); - connect(m_diagram, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); connect(m_diagram, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(adjustSceneRect())); connect(&(m_diagram -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle())); connect(diagram, SIGNAL(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation))); diff --git a/sources/diagramview.h b/sources/diagramview.h index 9425dd439..d97b13b53 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2019 The QElectroTech Team This file is part of QElectroTech. @@ -102,8 +102,6 @@ class DiagramView : public QGraphicsView bool gestures() const; signals: - /// Signal emitted after the selection changed - void selectionChanged(); /// Signal emitted after the selection mode changed void modeChanged(); /// Signal emitted after the diagram title changed diff --git a/sources/projectview.cpp b/sources/projectview.cpp index c74520e2a..422704795 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -56,11 +56,8 @@ ProjectView::ProjectView(QETProject *project, QWidget *parent) : Supprime les DiagramView embarquees */ ProjectView::~ProjectView() { - // qDebug() << "Suppression du ProjectView" << ((void *)this); - foreach(int id, m_diagram_ids.keys()) { - DiagramView *diagram_view = m_diagram_ids.take(id); - delete diagram_view; - } + for (auto dv_ : m_diagram_ids.values()) + dv_->deleteLater(); } /** diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index d85cedffa..9d26a479d 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1932,17 +1932,26 @@ void QETDiagramEditor::activateProject(ProjectView *project_view) { } /** - Gere la fermeture d'une ProjectView - @param project_view ProjectView fermee -*/ -void QETDiagramEditor::projectWasClosed(ProjectView *project_view) { + * @brief QETDiagramEditor::projectWasClosed + * Manage the close of a project. + * @param project_view + */ +void QETDiagramEditor::projectWasClosed(ProjectView *project_view) +{ QETProject *project = project_view -> project(); - if (project) { + if (project) + { pa -> elementsPanel().projectWasClosed(project); m_element_collection_widget->removeProject(project); undo_group.removeStack(project -> undoStack()); QETApp::unregisterProject(project); } + + //When project is closed, a lot of signal are emited, notably if there is an item selected in a diagram. + //In some special case, since signal/slot connection can be direct or queued, some signal are handled after QObject is deleted, and crash qet + //notably in the function Diagram::elements when she call items() (I don't know exactly why). + //set nullptr to "m_selection_properties_editor->setDiagram()" fix this crash + m_selection_properties_editor->setDiagram(nullptr); project_view -> deleteLater(); project -> deleteLater(); } @@ -2147,7 +2156,7 @@ void QETDiagramEditor::removeDiagramFromProject() { */ void QETDiagramEditor::diagramWasAdded(DiagramView *dv) { - connect(dv, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); + connect(dv->diagram(), &QGraphicsScene::selectionChanged, this, &QETDiagramEditor::selectionChanged, Qt::DirectConnection); connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions())); }