Remove a memory leak in the custom sort filter model example

Change-Id: Ie14f07bc2ee2215da2a81a75d816d4763fac085f
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Giuseppe D'Angelo 2014-12-23 13:03:27 +01:00
parent ceeb032de6
commit 8815a75ef0

View File

@ -91,15 +91,15 @@ bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
if (leftData.type() == QVariant::DateTime) {
return leftData.toDateTime() < rightData.toDateTime();
} else {
QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
static QRegExp emailPattern("[\\w\\.]*@[\\w\\.]*)");
QString leftString = leftData.toString();
if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
leftString = emailPattern->cap(1);
if(left.column() == 1 && emailPattern.indexIn(leftString) != -1)
leftString = emailPattern.cap(1);
QString rightString = rightData.toString();
if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
rightString = emailPattern->cap(1);
if(right.column() == 1 && emailPattern.indexIn(rightString) != -1)
rightString = emailPattern.cap(1);
return QString::localeAwareCompare(leftString, rightString) < 0;
}