From c3fa43513e32c5bd8c0ee9d703119a545a5b8bc6 Mon Sep 17 00:00:00 2001 From: Chris Lerner Date: Fri, 5 Apr 2024 13:01:46 +0200 Subject: [PATCH] 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.7 6.6 6.5 6.2 Change-Id: I7f25711785ec7a82852a0f37d9f096cc3af41576 Reviewed-by: Axel Spoerl --- examples/widgets/itemviews/addressbook/addresswidget.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp index bde1cdc3347..5b226793e4b 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.cpp +++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp @@ -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());