[Interest] QSettings doesn't save settings

Israel Brewster israel at ravnalaska.net
Thu Feb 11 20:39:20 CET 2016


On Feb 11, 2016, at 9:50 AM, Israel Brewster <israel at ravnalaska.net> wrote:
> 
> I have an app I built using Qt 5.5.1 on Mac OS X 10.11.1 (and perhaps other versions, but that's where I'm testing), which is sandboxed. When I run the app, it creates the sandbox directory just fine, however QSettings never creates the settings file. I am using QSettings at its most basic form, that is I create the settings object like so:
> 
> QSettings settings("israelbrewster","epunchclockstd");
> 
> and then use it. However, even if I call sync(), no settings file is ever created, and every time I create a settings object, I get an empty one - none of the settings I have saved ever show up. Calling settings.status() shows "NoError", which doesn't help and obviously isn't correct.
> 
> HOWEVER, if I first manually create the settings file from a terminal window, it works fine - settings are saved and can be changed at will. It's just the initial creation that doesn't appear to be working. How can I fix this?

Quick follow-up: This is apparently not an issue with an incorrect path in QSettings or with the app not having write privileges to the specified directory. I added the following code immediately after declaring the QSettings object:

    QFile prefsFile(settings.fileName());
    if(!prefsFile.exists()){
        prefsFile.open(QIODevice::WriteOnly); //try to create the settings file
        prefsFile.close();
    }

...and it works. The file is created, and after that I can set and retrieve settings as expected. This is quite the ugly workaround, however - QSettings should be creating the file if needed already. So at least I have a workaround that *appears* to be functional, but it would be nice to know why this is happening and how to *properly* fix it. Thanks.
-----------------------------------------------
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
-----------------------------------------------

> 
> -----------------------------------------------
> Israel Brewster
> Systems Analyst II
> Ravn Alaska
> 5245 Airport Industrial Rd
> Fairbanks, AK 99709
> (907) 450-7293
> -----------------------------------------------
> 
> 
> <Israel Brewster.vcf>
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest




More information about the Interest mailing list