![]() ![]() If it does, we display the first contact otherwise, we display a QMessageBox to inform the user about the problem. To display the contacts that have been read from the file, we must first validate the data obtained to ensure that the file we read from actually contains address book contacts. Tr( "The file you are attempting to open contains no contacts.")) QMessageBox ::information( this, tr( "No contacts in file") , We declare two public slots, saveToFile() and loadFromFile(), as well as two QPushButton objects, loadButton and saveButton. Reading from a QIODevice and writing to it is as simple as opening the stream - with the respective device as a parameter - and reading from or writing to it. QFile is a subclass of the more general QIODevice class which represents many different kinds of devices.Ī QDataStream object is used to serialize binary data so that it can be stored in a QIODevice and retrieved again later. Qt provides a number of classes for input and output, but we have chosen to use two which are simple to use in combination: QFile and QDataStream.Ī QFile object represents a file on disk that can be read from and written to. This part covers the Qt file handling features we use to write loading and saving routines for the address book.Īlthough browsing and searching the contact list are useful features, our address book is not complete until we can save existing contacts and load them again at a later time. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |