Merge pull request #1901 from PhenomRetroShare/Fix_ClearLayout

Fix Clear Layout methode.
This commit is contained in:
defnax 2020-05-08 17:20:01 +02:00 committed by GitHub
commit 477f0a8a76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,7 @@
#include <QFontDialog> #include <QFontDialog>
#include "misc.h" #include "misc.h"
#include "util/rsdebug.h"
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB) // return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
// use Binary prefix standards from IEC 60027-2 // use Binary prefix standards from IEC 60027-2
@ -416,12 +417,17 @@ void misc::clearLayout(QLayout * layout) {
while (auto item = layout->takeAt(0)) 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(); widget->deleteLater();
if (auto *spacer = item->spacerItem()) if (spacer)
delete spacer; delete spacer;
clearLayout(item->layout()); //delete item;//Auto deleted by Qt.
delete item;
} }
} }