From 5b6a8235087849281c9b4e037e78712eae81e841 Mon Sep 17 00:00:00 2001 From: lanthora Date: Mon, 6 May 2024 22:41:45 +0800 Subject: [PATCH] fix: invalid configuration generated when deleting a network --- candyitem.cc | 2 +- detailarea.cc | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/candyitem.cc b/candyitem.cc index 7bd516c..9ae2979 100644 --- a/candyitem.cc +++ b/candyitem.cc @@ -18,6 +18,7 @@ CandyItem::CandyItem() setSizeHint(QSize(0, 40)); candy = std::shared_ptr(candy_client_create(), candy_client_release); + candy_client_set_address_update_callback(candy.get(), address_update_callback); KeepAlive::instance().add(candy); } @@ -47,6 +48,5 @@ void CandyItem::update() candy_client_set_localhost(candy.get(), toStdString(settings.value("localhost")).c_str()); settings.endGroup(); - candy_client_set_address_update_callback(candy.get(), address_update_callback); KeepAlive::instance().restart(candy); } diff --git a/detailarea.cc b/detailarea.cc index 0cc31eb..9039d8a 100644 --- a/detailarea.cc +++ b/detailarea.cc @@ -137,11 +137,13 @@ void DetailArea::remove() { removeButton->setEnabled(false); int row = candyList->currentRow(); - CandyItem *item = dynamic_cast(candyList->takeItem(row)); - settings.remove(item->text()); - settings.sync(); + CandyItem *item = dynamic_cast(candyList->takeItem(row)); + QString name = item->text(); delete item; + settings.remove(name); + settings.sync(); + if (candyList->count() == 0) { reset(); } else if (candyList->count() > row) {