![]() |
Home · Overviews · Examples |
In this chapter, we look at ways to modify the contents of contact stored in the address book application.
In this chapter, we define the Mode enum with three different values:
To remove a contact from the address book, we implement the removeContact() function. This function checks to see if the contact exists in contacts.
Missing snippet: tutorials/addressbook/part4/addressbook.cpp.
If it does, we display a QMessageBox, to confirm the removal with the user. Once the user has confirmed, we call previous() to ensure that the user interface shows another contact, and we remove the contact using QMap's remove() function. As a courtesy, we display a QMessageBox to inform the user. Both the message boxes used in this function are shown below:
Each of the push buttons is then enabled or disabled, depending on the current mode. The code for AddingMode and EditingMode is shown below: Missing snippet: tutorials/addressbook/part4/addressbook.cpp. For NavigationMode, however, we include conditions within the parameters of the QPushButton::setEnabled(). This is to ensure that the editButton and removeButton push buttons are enabled when there is at least one contact in the address book; nextButton and previousButton are only enabled when there is more than one contact in the address book. Missing snippet: tutorials/addressbook/part4/addressbook.cpp. By performing the task of setting the mode and updating the user interface in the same function, we avoid the possibility of the user interface getting "out of sync" with the internal state of the application.
Copyright © 2008 Trolltech | Trademarks | Qt Jambi 4.4.0_01 |