I think you are trying to solve a problem that does not exist. You create a QSettings object when you need it, use it, and discard it. There is no need to keep a QSettings instance in a global variable. You can set some common values used by QSettings once (usually in main) to make using QSettings elsewhere trivial.
int main(...) {
...
}
// elsewhere
void foo() {
QString label
= settings.
value("Label",
"Default value").
toString();
}
void bar() {
QString label
= settings.
value("OtherLabel",
"Default value").
toString();
}
int main(...) {
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("MySoft");
QCoreApplication::setOrganizationDomain("mysoft.com");
QCoreApplication::setApplicationName("Star Runner");
...
}
// elsewhere
void foo() {
QSettings settings;
QString label = settings.value("Label", "Default value").toString();
}
void bar() {
QSettings settings;
QString label = settings.value("OtherLabel", "Default value").toString();
}
To copy to clipboard, switch view to plain text mode
QSettings is for storing relatively small amounts of information.
The Qt translation mechanism may be a better way to handle the label text if you are trying to achieve for example French/Arabic versions of the labels.
Bookmarks