In my .cpp I'm using QSettings.
This worked before, in Qt 4.8:
#include <QSettings>
----------
QSettings settings;
settings.setValue("time_axis_direction", 1);
int test_var = settings.value("time_axis_direction").toInt();
----------
In test_var
the program returns 0, what's the cause?
I used Qt with VS Add-In.
QSettings stores settings. Each setting consists of a QString that specifies the setting's name (the key) and a QVariant that stores the data associated with the key. To write a setting, use setValue().
The QSettings class provides persistent platform-independent application settings. Users normally expect an application to remember its settings (window sizes and positions, options, etc.) across sessions. This information is often stored in the system registry on Windows, and in XML preferences files on Mac OS X.
According to the docs, you have to set organization name and application name:
QCoreApplication::setOrganizationName("My Organization");
QCoreApplication::setApplicationName("My Application");
QSettings settings;
Or right in the constructor:
QSettings settings("My Organization", "My Application");
This will create HKCU\SOFTWARE\My Organization\My Application
registry entry to store your settings (on Windows).
If QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName() has not been previously called, the QSettings object will not be able to read or write any settings, and status() will return AccessError.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With