Details
-
Suggestion
-
Resolution: Done
-
P3: Somewhat important
-
4.6.0
-
None
-
14e17d5fe5f925a768aab9db9401e04bbaca224d
Description
In addressbook tutorial
(link http://doc.trolltech.com/4.6/tutorials-addressbook-part4-addressbook-cpp.html)
we have several IF statments, example below:
??
void AddressBook::submitContact()
{
QString name = nameLine->text();
QString address = addressText->toPlainText();
if (name == "" || address == "")
{ QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); }if (currentMode == AddingMode) {
if (!contacts.contains(name))
{ contacts.insert(name, address); QMessageBox::information(this, tr("Add Successful"), tr("\"%1\" has been added to your address book.").arg(name)); }else
{ QMessageBox::information(this, tr("Add Unsuccessful"), tr("Sorry, \"%1\" is already in your address book.").arg(name)); }??
Fist IF statement should prevent from adding new entry in address book without some text in nameLine and in addressText.
But even it wrong condition function doesn't stops, e.g. I can add entry with for example empty address. Therefore I recomend to add return if first condition is met:
void AddressBook::submitContact()
{
QString name = nameLine->text();
QString address = addressText->toPlainText();
if (name == "" || address == "")
{ QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); *return*; }