Solved Configure QSettings ((QSettings::Format and QSettings::Scope )
-
@VRonin said in Configure QSettings ((QSettings::Format and QSettings::Scope ):
Just subclass QSettings
Ugh!
Can't we have something like this instead?*QSettings mySettings() { return QSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(...)); }
*c++17 and later
Use directly on initialization:
QSettings settings = mySettings();
-
@kshegunov said in Configure QSettings ((QSettings::Format and QSettings::Scope ):
Can't we have something like this instead?*
Potato/Potatoe
-
@VRonin said in Configure QSettings ((QSettings::Format and QSettings::Scope ):
Potato/Potatoe
The point is to avoid type proliferation, I know you know that's a thing. Why derive anything if you don't have to; you're not changing any behavior here!
-
@kshegunov don't you still need a class for this, or do you advocate a global free floating function here?
-
@J-Hilk said in Configure QSettings ((QSettings::Format and QSettings::Scope ):
@kshegunov don't you still need a class for this, or do you advocate a global free floating function here?
A normal C-like function,
inline
-d ideally. Why would you make a class for this? -
@kshegunov you can't as QSettings is a QObject.It does work with C++17, see @kshegunov answer below.
-
@hbatalha QSettings has static setDefaultFormat that you can call along those other
set*
functions, so the only part missing is the default scope, but it's not so bad I think?QSettings settings(QSettings::SystemScope);
It does feel like it would be kinda completing the API nicely if there was also something like static
QSettings::setDefaultScope(QSettings::Scope)
. You could file a feature request on bugreports.qt.io if that's something you'd like to see in future versions. -
@SGaist said in Configure QSettings ((QSettings::Format and QSettings::Scope ):
@kshegunov you can't as QSettings is a QObject.
Au contraire mon ami! Excuse the bad friench, but the point is C++17 mandates RVO, so this compiles and runs correctly with g++. You don't make no copies here.
-
The French part is completely correct :-)
I missed the C++17 bits. My bad ! -
@SGaist said in Configure QSettings ((QSettings::Format and QSettings::Scope ):
The French part is completely correct :-)
Good that my initial (and rather inexcusable) error was caught on time ;)
-
@Chris-Kawa said in Configure QSettings ((QSettings::Format and QSettings::Scope ):
QSettings has static setDefaultFormat that you can call along those other set* functions, so the only part missing is the default scope, but it's not so bad I think?
That's a good idea, I read it in the doc but misunderstood its role. I will try this approach and @kshegunov's answer and get back to you.