desktop: do own memory management of quadrant widgets

The memory management of the quadrant widgets is a total mess:
When setting the widget, the QSplitters take ownership, which
means that they will delete the widget in their destructor.

This is inherently incompatible with singletons, which must
not be deleted.

To avoid all these troubles, remove the widgets from the
QSplitters in the desctructor of the MainWindow. This of
course means that we now have to take care about deletion
of the widgets.

For local widgets use std::unique_ptr, for singletons use
a static variable that is deleted on application exit.

Sadly, for the map widget we can't use a normal singleton,
because the QML MapWidget's memory management is buggy.
Add a comment in the source code explaining this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-12-18 12:01:36 +01:00 committed by Dirk Hohndel
parent 8a36a100ce
commit 64dae43bdd
3 changed files with 59 additions and 43 deletions

View file

@ -116,6 +116,15 @@ void MapWidget::divesChanged(const QVector<dive *> &, DiveField field)
reload();
}
// Sadly, for reasons out of our control, we can't use a normal singleton for the
// map widget: In a standard singleton, the object is freed after main() exits.
// However, if there is an animation running (map zooming), the thread is
// terminated, when the QApplication object is destroyed, which is before main()
// exits. The thread has a QQmlAnimationTimer that is freed. However, the map widget
// then tries to free the object itself, leading to a crash. Clearly, a bug in
// the QML MapWidget / QtQuick ecosystem.
// To solve this, the mainwindow will destroy the map widget and in the destructor
// the reference is cleared. Sad.
MapWidget::~MapWidget()
{
m_instance = NULL;