Persistent Settings
QSettings (Section 11.2.1)
Suppose you want to be able to support multiple playlist formats and also remember the last format used. Or, suppose you want to remember the last opened directory for MP3 files and, independently, the last opened directory for playlist files.
Settings are simply a persistent mapping of name-value pairs. The names can be anything we like, but using meaningful hierarchical names will aid greatly in organization. In Qt on *nix, people tend to use the slash ("/") as a namespace delimiterin contrast to Java, which uses a dot (".").
In this exercise, we will implement persistent settings by reusing QSettings. A QSettings object reads/stores its settings from/to different places depending on the operating system.
The first three settings that the program needs to remember across executions are listed below. Write a TestCase of the settings class that loads, changes, saves, loads again, and checks whether the values were changed.
- playlistmgr/outputformat=(extm3u|xml)
- playlistmgr/lastopendir=last opened directory
- playlistmgr/playlistdir=last opened playlist directory
Think of other properties/settings you might want to set from the application that must persist across executions.
Категории