aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2019-08-18 14:13:34 +0200
committerGerald Combs <gerald@wireshark.org>2019-08-19 19:58:49 +0000
commit22b5495485b3359fd62a39bedf2251c48f411a87 (patch)
tree9f04f5f7659f4b4b7f2e5a5d57038117477e5f64 /ui
parent97a9c7a12e7abb553e87a83ef6338123c847a6f9 (diff)
Qt: Fix CredentialsModel::clear()
The last parameter to beginRemoveRows() is the last row index, not the number of rows. The QAbstractItemModel::beginRemoveRows() source code expliticly checks if the value is smaller than row count. Do not emit beginRemoveRows() if the model is empty as it does not make sense and it is impossible to pass the QAbstractItemModel assertions in such case. Emit endRemoveRows() when finished instead of endInsertRows(). Change-Id: I93be4820b1ea0fbb5c0f3cd28edca329b4017814 Reviewed-on: https://code.wireshark.org/review/34318 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/models/credentials_model.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/ui/qt/models/credentials_model.cpp b/ui/qt/models/credentials_model.cpp
index 99327d9f85..23c1e48dd0 100644
--- a/ui/qt/models/credentials_model.cpp
+++ b/ui/qt/models/credentials_model.cpp
@@ -117,14 +117,16 @@ void CredentialsModel::addRecord(tap_credential_t* auth)
void CredentialsModel::clear()
{
- emit beginRemoveRows(QModelIndex(), 0, rowCount());
- for (QList<tap_credential_t*>::iterator itr = credentials_.begin(); itr != credentials_.end(); ++itr) {
- g_free((*itr)->username);
- g_free((*itr)->info);
- delete *itr;
+ if (!credentials_.isEmpty()) {
+ emit beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+ for (QList<tap_credential_t*>::iterator itr = credentials_.begin(); itr != credentials_.end(); ++itr) {
+ g_free((*itr)->username);
+ g_free((*itr)->info);
+ delete *itr;
+ }
+ credentials_.clear();
+ emit endRemoveRows();
}
- credentials_.clear();
- emit endInsertRows();
}
QVariant CredentialsModel::headerData(int section, Qt::Orientation orientation, int role) const