QSettings::setPath() being ignored

Discuss anything related to product development
Post Reply
seasoned_geek
Posts: 261
Joined: Thu Jun 11 2020 12:18 pm

QSettings::setPath() being ignored

Post by seasoned_geek »

Per this doc for setPath()
https://www.copperspice.com/docs/cs_api/class_qsettings.html#acd273b6e9d88af199eb278231a5bd24a

Code: Select all

    QStringList configLocations = QStandardPaths::standardLocations( QStandardPaths::AppConfigLocation );
    qDebug() << "AppConfigLocation: " << configLocations << "\n";
    QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configLocations[0] );
should cause config files to be created

Code: Select all

AppConfigLocation:  (/home/roland/.config/LogikalSolutions/RedDiamond, /etc/xdg/xdg-ubuntu/LogikalSolutions/RedDiamond, /etc/xdg/LogikalSolutions/RedDiamond) 
in /home/roland/.config/LogikalSolutions/RedDiamond
when

Code: Select all

    m_settings = new QSettings( m_configName, QSettings::IniFormat, this );
is used. They actually get created here:

Code: Select all

roland@roland-HP-EliteDesk-800-G2-SFF:~/.config$ ls LogikalSolutions
RedDiamondDefault.conf  RedDiamondLastUsed.conf
roland@roland-HP-EliteDesk-800-G2-SFF:~/.config$ 
even forcing "/" onto the end of the directory path will not fix it.

The deprecated setUserIniPath() works perfectly.
ansel
Posts: 154
Joined: Fri Apr 10 2015 8:23 am

Re: QSettings::setPath() being ignored

Post by ansel »

We took a look at the constructors for QSettings. If you are using the constructor where the first parameter is a filename, the file will be created relative to the current working directory. One option is to specify the full path as part of the filename. There are other constructors which may have been easier to use for your application.

As you noted the documentation is a bit unclear and we are going to enhance it and add an example. New API docs will be uploaded by the end of this week.
Ansel Sermersheim
CopperSpice Cofounder
seasoned_geek
Posts: 261
Joined: Thu Jun 11 2020 12:18 pm

Re: QSettings::setPath() being ignored

Post by seasoned_geek »

ansel wrote: Tue Sep 13 2022 2:50 am We took a look at the constructors for QSettings. If you are using the constructor where the first parameter is a filename, the file will be created relative to the current working directory. One option is to specify the full path as part of the filename. There are other constructors which may have been easier to use for your application.

As you noted the documentation is a bit unclear and we are going to enhance it and add an example. New API docs will be uploaded by the end of this week.
The deprecated method works perfectly. The new methods not-so-much. That was really the gist of it.
Post Reply