Hmm... Here's the code of the function in full:
void AddressBook::previous()
{
QMap<QString, QString>::iterator i = contacts.find(name);
if (i == contacts.end()) {
nameLine->clear();
addressText->clear();
return;
}
if (i == contacts.begin())
i = contacts.end();
i--;
nameLine->setText(i.key());
addressText->setText(i.value());
}
void AddressBook::previous()
{
QString name = nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i == contacts.end()) {
nameLine->clear();
addressText->clear();
return;
}
if (i == contacts.begin())
i = contacts.end();
i--;
nameLine->setText(i.key());
addressText->setText(i.value());
}
To copy to clipboard, switch view to plain text mode
It seems to me that when the iterator is declared, and assigned to contacts.find(name), it will only get the contacts.end() "value" if the QString name isn't found in the QMap. However, how could this situation be possible?
Bookmarks