diff options
author | Chris Lerner <chris.lerner@qt.io> | 2024-04-05 13:01:46 +0200 |
---|---|---|
committer | Chris Lerner <chris.lerner@qt.io> | 2024-04-11 00:12:19 +0200 |
commit | c3fa43513e32c5bd8c0ee9d703119a545a5b8bc6 (patch) | |
tree | 90321ed4a5ab75108eee64b51c040671a54ff74f | |
parent | b79cb3dd659c71560dd0324893cbdfe41a42f9dc (diff) |
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 <axel.spoerl@qt.io>
-rw-r--r-- | examples/widgets/itemviews/addressbook/addresswidget.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp index bde1cdc334..5b226793e4 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()); |