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 92e483c855
commit fc292bd788

View file

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