From f41fa2ebe291c20af94ac405d89df5519af69816 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sun, 3 May 2020 20:33:37 +0200 Subject: [PATCH] Fix Clear Layout methode. Pointer seems to be deleted by Qt when last children is removed. --- retroshare-gui/src/util/misc.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/util/misc.cpp b/retroshare-gui/src/util/misc.cpp index 4bcfd7149..9539ebd5a 100644 --- a/retroshare-gui/src/util/misc.cpp +++ b/retroshare-gui/src/util/misc.cpp @@ -28,6 +28,7 @@ #include #include "misc.h" +#include "util/rsdebug.h" // return best userfriendly storage unit (B, KiB, MiB, GiB, TiB) // use Binary prefix standards from IEC 60027-2 @@ -416,12 +417,17 @@ void misc::clearLayout(QLayout * layout) { while (auto item = layout->takeAt(0)) { - if (auto *widget = item->widget()) + //First get all pointers, else item may be deleted when last object removed and get SIGSEGV + auto *widget = item->widget(); + auto *spacer = item->spacerItem(); + //Then Clear Layout + clearLayout(item->layout()); + //Last clear objects + if (widget) widget->deleteLater(); - if (auto *spacer = item->spacerItem()) + if (spacer) delete spacer; - clearLayout(item->layout()); - delete item; + //delete item;//Auto deleted by Qt. } }