summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-08-03 14:08:04 +0300
committerMarc Mutz <marc.mutz@kdab.com>2016-08-12 08:28:07 +0000
commitc38ac3dab8cbbdb494e09ccebe93c4e57a9987c3 (patch)
treea6c217600bd936c0b07c5e908cf1f4396a42eb42
parentb57f743c469f16f0c9ad5a9f0182454b74deff97 (diff)
tst_QStringListModel: don't leak memory when tests fail
Simply allocate objects on the stack instead of the heap. Change-Id: Ic047d78e49668878821cce1c8ab599a8551b6476 Reviewed-by: David Faure <david.faure@kdab.com>
-rw-r--r--tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
index 60952616d5..efb9f8384c 100644
--- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
@@ -139,22 +139,19 @@ void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved()
QFETCH(QStringList, aboutto);
QFETCH(QStringList, res);
- QStringListModel *model = new QStringListModel(input);
- QModelListener *pListener = new QModelListener(&aboutto, &res, model);
- pListener->connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
- pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) );
+ QStringListModel model(input);
+ QModelListener listener(&aboutto, &res, &model);
+ connect(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
+ &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)));
- pListener->connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
- pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) );
+ connect(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)));
- model->removeRows(row,count);
+ model.removeRows(row, count);
// At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
-
- delete pListener;
- delete model;
}
void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted_data()
@@ -203,22 +200,19 @@ void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted()
QFETCH(QStringList, aboutto);
QFETCH(QStringList, res);
- QStringListModel *model = new QStringListModel(input);
- QModelListener *pListener = new QModelListener(&aboutto, &res, model);
- connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
- pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) );
+ QStringListModel model(input);
+ QModelListener listener(&aboutto, &res, &model);
+ connect(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
+ &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)));
- connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
- pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) );
+ connect(&model, SIGNAL(rowsInserted(QModelIndex,int,int)),
+ &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)));
- model->insertRows(row,count);
+ model.insertRows(row, count);
// At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
-
- delete pListener;
- delete model;
}
void tst_QStringListModel::setData_emits_both_roles_data()