O'Reilly logo

openFrameworks Essentials by Denis Perevalov, Igor Tatarnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing the autosave feature

Autosaving can be implemented by saving the GUI state to a file when the project ends, and loading the GUI state from this file on project startup. To accomplish this, perform the following steps:

  1. Declare the new exit() function in the ofApp class:
    void exit();
  2. Then, add its definition to the ofApp.cpp file, as follows:
    void ofApp::exit() {
      gui.saveToFile( "settings.xml" );
    }

    openFrameworks calls the exit() function right before finishing the project. So, this function saves the state of the gui elements to the settings.xml file, which is located in the bin/data folder of the project.

  3. To load the gui state at startup, add the following line to the end of the setup() function:
    gui.loadFromFile( "settings.xml" );
    

Autosave ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required