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
5
votes
1 answer

QSettings clear, what does it do?

The doc said about the QSettings::clear function as: Removes all entries in the primary location associated to this QSettings object. Entries in fallback locations are not removed. But what does this mean? what's the primary location and fall…
Nyaruko
  • 4,329
  • 9
  • 54
  • 105
5
votes
1 answer

How to stop QSettings altering the order of key=value pairs in setting file?

In my program I have a Microsoft's INI style settings/configuration file that is created, edited and stored using the convenient QSettings class but the user may manually edit this file using the program itself, or any text editor she desires like…
max
  • 2,627
  • 1
  • 24
  • 44
4
votes
2 answers

whats the advantage of QSettings over just using a dict?

QSettings seems like a great thing in C++, it's essentially a flexible hash table where the key is a string and the value is a QVariant, so it can be quite a few types. However, in Python we already have this, its a dictionary. So I ask, what…
Kevin S
  • 930
  • 10
  • 19
4
votes
2 answers

Cannot get QSettings to read from custom storage format

I'm trying to create a custom format for QSettings, but I can't get it to read from the storage. In the code below, if I run settings.setValue("test", 123"), it correctly calls the write function and prints Calling writeSqlite. However, if I try…
laurent
  • 88,262
  • 77
  • 290
  • 428
4
votes
2 answers

Cannot read boolean from ini file

I have problem with loading boolean from ini file in PyQt5 app. #!/usr/bin/python3 # -*- coding: utf-8 -*- import sys from PyQt5 import QtCore from PyQt5.QtCore import QSettings, QVariant from PyQt5.QtWidgets import ( QApplication, QCheckBox,…
przemekk
  • 351
  • 3
  • 10
4
votes
4 answers

How can I store a password in my Qt application?

How can I store a password in my Qt application? Is there no ready to use library by Qt ? Currently I store all my application configurations by means of QSettings.
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
4
votes
1 answer

Can i read from .ini file which located in resources files?

#include "mainwindow.h" #include "ui_mainwindow.h" #include #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QSettings * qsettings = new…
ratojakuf
  • 708
  • 1
  • 11
  • 21
4
votes
3 answers

QSettings - reading INI file

I create an INI file and then try to read it. There is no compile errors and the file is there but I'm not receiving any data in my QStringList QFile checkConfig(configPath); if(checkConfig.exists()) { QSettings* settings = new…
rreeves
  • 2,408
  • 6
  • 39
  • 53
3
votes
1 answer

Read QByteArray setting written by QSetting within different Qt version.

QByteArray is serialized in different formats on the file system if the different version of Qt library is used (say 4.5.2 against 4.7.1). I use the QSettings in my application to store the some binary data in the .ini file. Now application is…
MedBrother
  • 31
  • 2
3
votes
1 answer

Check if QSettings is using the default value

is there a way that I can check whether QSettings is using the default value? For example: def setup_ui(self): self.user_input = QtGui.QLineEdit() self.user_input.setText("Input something...") ... ... # Check for any stored…
dissidia
  • 1,531
  • 3
  • 23
  • 53
3
votes
2 answers

Printing a PDF file from Qt

I have found following code snippet which works as my expectation, but the problem is that, when a PDF file is open and user print the PDF file with some other printer from the PDF reader and not close the PDF reader and again print the PDF file…
3
votes
1 answer

Unix Qt 5.6 QSettings cannot find QSettings::SystemScope configuration file

Link to Qt Bug Report: QTBUG-53313 Moving from Qt 5.5 to Qt 5.6 presents an issue with QSettings where it cannot find the QSettings configuration file at the system scope. In main.cpp below, QSettings is initialized various ways, then its properties…
vincent
  • 1,370
  • 2
  • 13
  • 29
3
votes
2 answers

Qt - pyside - saveGeometry() saveState()

I have a Qt program and currently I use the Qsettings.saveGeometry() and Qsettings.saveState() functions to allow the program to restore the layout that the user set in the previous session. However not all geometry is saved, only the main window…
Ron
  • 522
  • 1
  • 3
  • 16
3
votes
1 answer

QSettings replaces slashes with backslashes (registry)

I read the registry with QSettings. The key I want to read is this: HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS (Updated on 8/1/2015 02:45:41) Since the key name Source OS (Updated on 8/1/2015 02:45:41) is dynamic, I just open QSettings…
wutzebaer
  • 14,365
  • 19
  • 99
  • 170
3
votes
3 answers

Reading application settings best practice

In my desktop app I use QSettings to persist various application values. For example, main form position, recent documents, connection paramenters and some things that alter the way the application behaves, for example "don't show this message…
Michael Vincent
  • 1,620
  • 1
  • 20
  • 46
1
2
3
12 13