From 16aa761e86016328290db4ebc0d0c2e2717a9551 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 13 Mar 2022 18:41:45 +0100 Subject: [PATCH] core: make the QUndoStack a "global object" Thus, it will be freed before application exit. Freeing it later led to crashes. Signed-off-by: Berthold Stoeger --- commands/command_base.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/commands/command_base.cpp b/commands/command_base.cpp index fe4cf7840..26855f0e6 100644 --- a/commands/command_base.cpp +++ b/commands/command_base.cpp @@ -1,13 +1,14 @@ // SPDX-License-Identifier: GPL-2.0 #include "command_base.h" +#include "core/globals.h" #include "core/qthelper.h" // for updateWindowTitle() #include "core/subsurface-qt/divelistnotifier.h" #include namespace Command { -static QUndoStack undoStack; +static QUndoStack *undoStack; // forward declaration QString changesMade(); @@ -15,39 +16,40 @@ QString changesMade(); // General commands void init() { - QObject::connect(&undoStack, &QUndoStack::cleanChanged, &updateWindowTitle); + undoStack = make_global(); + QObject::connect(undoStack, &QUndoStack::cleanChanged, &updateWindowTitle); changesCallback = &changesMade; } void clear() { - undoStack.clear(); + undoStack->clear(); } void setClean() { - undoStack.setClean(); + undoStack->setClean(); } bool isClean() { - return undoStack.isClean(); + return undoStack->isClean(); } // this can be used to get access to the signals emitted by the QUndoStack QUndoStack *getUndoStack() { - return &undoStack; + return undoStack; } QAction *undoAction(QObject *parent) { - return undoStack.createUndoAction(parent, QCoreApplication::translate("Command", "&Undo")); + return undoStack->createUndoAction(parent, QCoreApplication::translate("Command", "&Undo")); } QAction *redoAction(QObject *parent) { - return undoStack.createRedoAction(parent, QCoreApplication::translate("Command", "&Redo")); + return undoStack->createRedoAction(parent, QCoreApplication::translate("Command", "&Redo")); } QString diveNumberOrDate(struct dive *d) @@ -85,8 +87,8 @@ QString getListOfDives(QVector dives) QString changesMade() { QString changeTexts; - for (int i = 0; i < undoStack.index(); i++) - changeTexts += undoStack.text(i) + "\n"; + for (int i = 0; i < undoStack->index(); i++) + changeTexts += undoStack->text(i) + "\n"; return changeTexts; } @@ -95,7 +97,7 @@ bool execute(Base *cmd) { if (cmd->workToBeDone()) { executingCommand = true; - undoStack.push(cmd); + undoStack->push(cmd); executingCommand = false; emit diveListNotifier.commandExecuted(); return true;