fixed segfault on dir change

This commit is contained in:
2024-06-27 15:27:11 +02:00
parent a3cabf4e82
commit abc97d95ef

View File

@@ -10,12 +10,12 @@ GridItemView::GridItemView(QWidget* parent)
connect(fileController, &FileController::pathChanged, this, connect(fileController, &FileController::pathChanged, this,
[this, mainLayout](const std::filesystem::path path) { [this, mainLayout](const std::filesystem::path path) {
while (mainLayout->count( )) { // No, QT Does not offer a better way to clear a layout, at least this solution doesnt segfault
QWidget* widget = mainLayout->itemAt(0)->widget( ); QLayoutItem* wItem;
if (widget) { while ((wItem = mainLayout->takeAt(0)) != 0) {
mainLayout->removeWidget(widget); if (wItem->widget( ))
delete widget; wItem->widget( )->setParent(nullptr);
} delete wItem;
} }
}); });
@@ -24,6 +24,8 @@ GridItemView::GridItemView(QWidget* parent)
auto w = new GridItem(path); auto w = new GridItem(path);
gridMap[path] = w; gridMap[path] = w;
connect(w, &GridItem::clicked, this, [this, path]( ) { connect(w, &GridItem::clicked, this, [this, path]( ) {
if (!std::filesystem::is_directory(path))
return;
emit fileController->updatePath(path); emit fileController->updatePath(path);
}); });
int pos = gridMap.size( ) - 1; int pos = gridMap.size( ) - 1;