Don't add any entry whose name doesn't start with a letter

In the Addressbook example, any entry whose name doesn't start
with a letter will not appear in any of the categories,
but it will still exist. These entries would make the
"There are currently no contacts in your address book" page
disappear even when no entries could be found in the categories.

Check if a new entry has a name that doesn't start with a letter,
and if so, don't add it as a contact. Also, notify user that names
must start with a letter when this happens.

Fixes: QTBUG-124254
Pick-to: 6.6 6.5 6.2
Change-Id: I7f25711785ec7a82852a0f37d9f096cc3af41576
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit c3fa43513e32c5bd8c0ee9d703119a545a5b8bc6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Chris Lerner 2024-04-05 13:01:46 +02:00 committed by Qt Cherry-pick Bot
parent 79cb221f96
commit 37d8317638

View File

@ -34,7 +34,10 @@ void AddressWidget::showAddEntryDialog()
//! [3]
void AddressWidget::addEntry(const QString &name, const QString &address)
{
if (!table->getContacts().contains({ name, address })) {
if (!name.front().isLetter()) {
QMessageBox::information(this, tr("Invalid name"),
tr("The name must start with a letter."));
} else if (!table->getContacts().contains({ name, address })) {
table->insertRows(0, 1, QModelIndex());
QModelIndex index = table->index(0, 0, QModelIndex());