Modify the My Movies application so that each Movie object can store an extra piece of information: a QString called "location", which is where the movie is located—for example, the room and shelf. Provide only saving and loading of binary Qt format .mqb files and export and import of XML files, so remove the code for saving and loading pickles and text files. Make sure that your new My Movies application can still read the original application's .mqb and .xml files, that is, files that do not have location data.
The moviedata module's Movie class will need an extra QString attribute, called "location". The MovieContainer class will need several small changes. You will need to have both an old and a current file version number so you know which kind you are dealing with. The formats() method should now return only the string *.mqb, or could be eliminated entirely. The save() and load() methods need to handle only .mqb files, and must account for the location and the different file versions. Similarly the exportXml() method and the two import XML methods must also account for the possible presence of <LOCATION> tags. The changes to the user interface should be obvious, so we won't list them.
None of these changes involves many lines of code, but some are subtle and will take a bit of care to get right. Make sure that you test your changes. For example, load in an old file in .mqb format, and import a file in the old .xml format. Add some locations and save the data in a new .mqb file and export as XML. Read both of these back in to check that everything works properly.
A model solution is provided in the files, chap08/mymovies_ans.pyw, chap08/ moviedata_ans.pyw, chap08/addeditmoviedlg_ans.ui, and chap08/addeditmoviedlg-_ans.py.
Was this article helpful?
Discover How You Can Quickly And Easily Dominate Google and YouTube... With Simple Cash Generating Videos. Did you know that YouTube is the second largest search website on the entire Internet? YouTube gets more daily searches than Bing and Yahoo. In fact, there is only one search engine that gets more action.