Fix crash on smartsearchbar : internal addresses weren't match to the number of count because of self result.

This commit is contained in:
Julien Wadel 2022-02-24 18:05:30 +01:00
parent 3824ecaa78
commit effe5eb3aa

View file

@ -62,7 +62,7 @@ SearchSipAddressesModel::~SearchSipAddressesModel(){
// -----------------------------------------------------------------------------
int SearchSipAddressesModel::rowCount (const QModelIndex &) const {
return std::max(mAddresses.count()-1,0);
return mAddresses.count();
}
QHash<int, QByteArray> SearchSipAddressesModel::roleNames () const {
@ -118,16 +118,10 @@ void SearchSipAddressesModel::searchReceived(std::list<std::shared_ptr<linphone:
if( linphoneFriend || address)
addresses << std::make_shared<SearchResultModel>(linphoneFriend,address );
}
// Fix crash on Qt 5.15.2 with endResetModel (index out of range).
if(mAddresses.size() > 0){// Workaround : remove all
beginRemoveRows(QModelIndex(), 0, mAddresses.size()-1);
mAddresses.clear();
endRemoveRows();
}
if( addresses.size() > 0){// Workaround : add new on cleanned base
beginInsertRows(QModelIndex(),0, addresses.size()-1);
mAddresses = addresses;
endInsertRows();
}
//--------------------------------------------------------------
beginResetModel();
mAddresses.clear();
mAddresses = addresses;
if(mAddresses.size() > 0 )// remove self
mAddresses.pop_back();
endResetModel();
}