Lesson 04 · Desktop Apps with Python & Qt
Desktop: Files, Dialogs & Settings
Give your desktop apps a memory: choose files with native QFileDialog dialogs, read and write them safely with with open, keep application state as JSON, and remember window geometry and recent files with QSettings.
Prerequisites: Desktop: Model/View Programming
Learning objectives
By the end of this lesson, you will be able to:
- Open and save files with QFileDialog's getOpenFileName and getSaveFileName, handling the cancel case
- Read and write text files with with open, an explicit encoding and graceful OSError handling
- Save and load application state as JSON, and recognize when JSON is the right home for data
- Store and restore window geometry, preferences and recent files with QSettings
- Track dirty state so a window never closes over unsaved work without asking first