Clear QML Settings on OS X

2015-02-17T21:38:51Z

I am working on a rewrite of my TinyTinyRSS client called FeedTheMonkey from PyQt which are bindings in Python for Qt to a real Qt application with a C++ backend and a QML frontend. You can check out the code on Github if you like.

I hope by doing so I will be able to port it to many more platforms like for example the new Ubuntu Phone without rewriting too much code. And besides that I would like to make the installation process much easier, right now you have to manually install Qt and Python and the bindings. I hope after the rewrite I will be able to offer a .app for OS X, a .exe for Windows and perhaps get it packaged for the normal Linux and BSD distros.

Anyway, I am using QSettings to save some application data within C++ and the new QML Settings which were added to Qt 5.4 which I use for my project. Those let you save data easily without the need to create and parse files, etc. you just get an object.

For C++

QSettings settings("net.jeena", "FeedTheMonkey");
settings.setValue("serverUrl", mServerUrl);
settings.sync();
// to get it back later on:
QString serverUrl = settings.value("serverUrl").toString();

Pretty neat, but what if you for some reason want to remove every settings value for a fresh start? QSettings has a clear() method which would kind of work but you would need to have a working application for that. What if you just want to remove the corresponding files?

I'm on OS X Yosemite and like the QSettings documentation described I was able to find the file ~/Library/Preferences/com.net-jeena.feedthemonkey.plist but when I removed it my application was still able to read from the settings file. After some searching the Internet I was able to find out that starting with OS X 10.9 the .plist Perference files are being cached in the applications process. You can flush the cache with help of:

killall -u jeena cfprefsd

For QML

// in the main() function
QGuiApplication app(argc, argv);
app.setOrganizationName("Jeena");
app.setOrganizationDomain("jeena.net");
app.setApplicationName("FeedTheMonkey");

// in main.qml
ApplicationWindow {
    id: app
    title: "FeedMonkey"
    Settings {
        id: settings
        category: "window"
        property alias x: app.x
        property alias y: app.y
        property alias width: app.width
        property alias height: app.height
    }
}

This way when you change the window position and size it will automatically be saved and when starting the application later on it will be read and set automatically back to those values. Very very nice. But again here, what if you want to remove those files? Sadly the QML Settings documentation doesn't mention anything about that, there is no clear() method, nothing.

What I did to find out where it saves the data was that I changed the application name to a long random ASCII string so be able to use the find command to find all files in the ~/Library directory which would be associated with my application. Here is what I found:

~/Library/Application Support/Jeena/FeedTheMonkey
~/Library/Caches/Jeena/FeedTheMonkey
~/Library/Preferences/net.jeena.FeedTheMonkey.plist

Removing those and again running killall -u jeena cfprefsd made it possible for me to do a fresh start.