Questions tagged [qsettings]

QSettings is a Qt class that provides an ability to store and use platform-independant settings for an application.

QSettings provides a very easy way to store, read and modify application settings in . Using this class is very simple.

The first thing to be done is creating an instance of QSettings. It gets 2 arguments which are the application's name, and the developer's company or organization. These are needed to name the settings files (on Unix-like systems) or the register branches (on Windows):

QSettings mySettings("myCompany","myAppName"); 

It is also possible to pre-set those values to get rid of the necessity of passing them every time a QSettings object is created. This can be done with QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName().

After a QSettings object is created, reading and writing settings is as easy as this:

//setting a value. The name should be QString, and the value can be a QVariant. 
mySettings.setValue("valueName", "value");
//reading a value:
mySettings.value("vaueName");

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

183 questions
44
votes
9 answers

QSettings - where is the location of the ini file?

I'm using QSettings to store some data as ini file in Windows. I want to see the ini file, but I don't know what is the location of the ini file. This is my code: QSettings *set = new QSettings(QSettings::IniFormat, QSettings::UserScope, "bbb",…
dubila
  • 1,099
  • 2
  • 10
  • 11
15
votes
1 answer

Writing and reading custom class to QSettings

I need to store instances of a custom class in the registry via QSettings. After reading from Qt's documentation, I think I have implemented the needed functions but I don't manage to save anything. Here's my custom class : class…
Ote
  • 301
  • 1
  • 5
  • 16
11
votes
1 answer

QSettings on OS X 10.9 - unable to locate/clear it

I have a Qt (4.8.5) based application running on OS X 10.9. The app uses QSettings class specifying app name and company. Plist file is created by QSetttings under: ~/Library/Preferences/com.company_name.app_name.plist The app works pretty fine in…
Thomas
  • 303
  • 2
  • 7
10
votes
4 answers

How to load settings in Qt app with QSettings

There are two possible ways: load all settings into some struct load values on-demand Which approach is better?
user1180567
  • 175
  • 1
  • 2
  • 8
9
votes
1 answer

Save UI settings with QSettings or QJson?

Saving UI settings with QSettings is cumbersome and buggy, because each time you must use setValue() and value() functions and also define groups, application name and organization which can be buggy in large applications: QSettings…
abdolahS
  • 663
  • 12
  • 35
9
votes
2 answers

QSettings - File chooser should remember the last directory

I upload a file from a location, then the next upload has to point the last uploaded location. How can I accomplish thus using QSettings?
user198725878
  • 6,266
  • 18
  • 77
  • 135
7
votes
3 answers

Check if a value registry exists with QSettings

What i'm trying to do is to check if a registry key (NOT VALUE, KEY) exists in the registry. I can't find any way to check that. Idea?
Kazuma
  • 1,371
  • 6
  • 19
  • 33
7
votes
1 answer

QSettings doesn't handle unicode well

I'm using QSettings to store some settings in an INI file. However, my program is not in English, so some of the settings contain Unicode strings. It seems that Qt writes INI files not in utf8 or utf16, but in some other encoding, the string "Привет…
Septagram
  • 9,425
  • 13
  • 50
  • 81
7
votes
2 answers

enum class in QVariant in QSettings

I have a problem with enum classes, QVariants and the QSettings class. There are enum class values that I want to store within a QVariant which goes into a QSettings instance. So, my code actually looks something like this: enum class Foo { …
CppChris
  • 1,226
  • 9
  • 14
7
votes
6 answers

QSettings is not working proprely on Qt under Android

I want to save some user credentials in my qt application that runs on Android. I use QSettings for this like so: QString appPath = QCoreApplication::applicationDirPath()+QLatin1Char('/'); set = new QSettings(appPath+"test", …
Lucian
  • 874
  • 11
  • 33
6
votes
2 answers

Save (already-existing) QSetting into an INI file

I want to save an alredy-existing QSettings object into some INI file for backup. The QSettings comes from the application's global settings, ie. it can be registry, ini file, etc. In case it helps, my context is: class Params { // All params…
Julien-L
  • 5,267
  • 3
  • 34
  • 51
6
votes
2 answers

Qt QSettings try to create ini file but none created why?

Im trying to create ini file that will hold me the configuration data, I have singletone class that setting the QSettings object like this : ... #DEFINE CONFIG_FILE_NAME "myconfig.ini" m_pSettings = new…
user63898
  • 29,839
  • 85
  • 272
  • 514
6
votes
3 answers

How to properly use QSettings

I want to use QSettings to save highscores but it doesn't work properly. I'm saving and reading those values in 2 different files. This is my code responsible for adding values into array: QSettings settings; settings.beginWriteArray("results"); int…
falsetto
  • 789
  • 2
  • 11
  • 35
5
votes
2 answers

Store settings of qt application using QSettings

Hello I have created an application using qt and I managed to save some of its settings using QSettings. void DoneIt::writeSettings() { QSettings settings("mycompany", "RightDoneIt"); settings.beginGroup("DoneIt"); …
Sharethefun
  • 804
  • 3
  • 17
  • 33
5
votes
1 answer

QSettings(Qt 5.4): setValue doesn't work properly

In my .cpp I'm using QSettings. This worked before, in Qt 4.8: #include ---------- QSettings settings; settings.setValue("time_axis_direction", 1); int test_var = settings.value("time_axis_direction").toInt(); ---------- In…
Saratery
  • 53
  • 5
1
2 3
12 13