robvdl/MapEditor — Issue #10: Recent projects menu
Author: robvdl
Created: 2012-02-02 06:40:14+00:00
State: open

We want to implement a recent projects (or recent files) menu. The list of recent projects can be stored as a QStringList type, which you can populate using the .append() method. We then write this QStringList variable to our QSettings object in mainwindow.cpp so it gets saved to our application's .ini file, QSettings is able to serialise the QStringList type automatically when it saves, as well as loading from it, so you don't have to worry about that.

There is an example in the Qt Docs: http://developer.qt.nokia.com/doc/qt-4.8/mainwindows-recentfiles.html

Please note that the example is a bit elaborate. They manually create the whole main window, and menus, and there is lots of code in there we don't need, so you are going to have to filter through it. We will however need to write some code to attach a sub menu, to the "stub" menu item in the .ui file for recent projects (attach a sub menu to this stub menu item). This way we can still have the rest of the menu in the .ui file, and just build the recent items menu dynamically. This is different from their example, since they generate the whole menu dynamically.

Have a good look at the example, and try to understand how it works first. You don't have to do it exactly the way they have done off course, for example, we will need to update the recent projects menu whenever a project is opened or created, their example is quite different.