Qt Settings: Difference between revisions
No edit summary |
(clean-up) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Developing_Qt]] | [[Category:Developing_Qt]] | ||
= Transitioning to app-specific settings = | = Transitioning to app-specific settings = | ||
Line 37: | Line 36: | ||
<code> | <code> | ||
QCoreApplication::QCoreApplication (int & | QCoreApplication::QCoreApplication (int & argc, char '''''' argv, const QString &organizationName, const QString organizationDomain, const QString &applicationName) | ||
</code> | </code> | ||
Latest revision as of 01:29, 24 March 2016
Transitioning to app-specific settings
Today, Qt stores its settings under the "Trolltech" organization name. This has several potentially adverse effects:
- Qt apps are rejected from the Mac app store since they write outside their own directory
- Completely uninstalling an application is hard; the settings file is left behind
- Unrelated apps fight over settings
We'd like to move to a model where Qt stores settings under the organization domain/name and application name ("app-local settings"). At the same time backwards compatibility is important and we would rather not abandon the old Trolltech settings. This does not have any effect on
QSettings
created by the application, only the settings used by Qt internally such as for the plugin cache.
Proposed Solution
Qt 4.8 will read Trolltech settings but not write to them. When reading settings, Qt looks for app-local settings first and the falls back to reading the Trolltech settings. Settings are written to the app-local location, under its own group name to prevent collisions with app settings. This should transition the Trolltech settings over to the new location the first time the application runs.
So far it looks like we need to set the application/org name outside of Qt for this to work. We have two mechanisms for this:
- qt.conf (cross-platform)
- .plist file Mac OS X
Alternative Solutions
setQtInternalSettingsMode
We considered adding API to
QCoreApplication
:
enum QtInternalSettngsMode { UserGlobalSettings, ApplicationLocalSettings };
QCoreApplication::setQtInternalSettingsMode(QtInternalSettngsMode mode);
However, we can't guarantee that this mode will be seen before
QSettings
is used by Qt. Also, changing the mode while Qt is running is not well-defined.
We can add a static version and document the intended use: Call this before constructing the QApplication, don't change the values later.
QApplication argument
QCoreApplication::QCoreApplication (int & argc, char '''''' argv, const QString &organizationName, const QString organizationDomain, const QString &applicationName)
This works from a technical standpoint - we are able to set the names before
QSettings
use them. One drawback is that it bloats the API.
QApplication
(QtGui) already has 6 constructors, adding
organizationName
etc. to all of them is probably not an good option.
Opt-in or Opt-out?
We need to support both setting modes. App-local settings seems to be a sensible default for pure Qt applications. KDE wants to keep the Trolltech settings to improve application startup. Clearly if the app author fails to specify the organization details we have to go with Trolltech settings.
Opt-in:
- Yet another option you have to set to get the desired behavior
- KDE does not have to change anything
- No default change in behavior means no surprises.
Opt-out:
- Apps get "better" behavior automatically
- We don't accumulate options in Qt
- KDE must set the mode in kde-qt
- Surprise! Qt 4.8 moved its settings. (but see the migration strategy above)
I'm currently in favor of Opt-out.
Use case: Designer startup
There is exactly one use of "Trolltech" during
QApplication
construction. In addition, Phonon writes settings to "kde.org"
/bin/Designer.app/Contents/MacOS/Designer
main entered
creating QApplication
QCoreApplication::init()
settings "apple.com" ""
settings "Trolltech" ""
settings "apple.com" ""
settings "apple.com" ""
QApplication constructor done
settings "Trolltech" "Designer"
settings "Trolltech" ""
settings "Trolltech" ""
settings "Trolltech" ""
settings "Trolltech" ""
settings "Trolltech" "Designer"
settings "Trolltech" ""
settings "apple.com" ""
settings "apple.com" ""
settings "apple.com" ""
settings "apple.com" ""
settings "kde.org" "libphonon"
settings "Trolltech" ""
settings "apple.com" ""
settings "Trolltech" ""
settings "apple.com" ""
Where does Qt use Trolltech settings?
22 locations according to git grep:
3rdparty/phonon/gstreamer/devicemanager.cpp: QSettings settings(QLatin1String("Trolltech"));
corelib/plugin/qfactoryloader.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
corelib/plugin/qlibrary.cpp: settings = new QSettings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/dialogs/qcolordialog.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/dialogs/qcolordialog.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/dialogs/qfiledialog.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/dialogs/qfiledialog.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/kernel/qapplication_mac.mm: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/kernel/qapplication_qws.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/kernel/qapplication_x11.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/kernel/qapplication_x11.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/painting/qprintengine_ps.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/styles/qs60style_s60.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/styles/qs60style_s60.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
gui/text/qfontengine_x11.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
network/socket/qlocalserver_tcp.cpp: QSettings settings(QLatin1String("Trolltech"), QLatin1String("Qt"));
network/socket/qlocalserver_tcp.cpp: QSettings settings(QLatin1String("Trolltech"), QLatin1String("Qt"));
network/socket/qlocalserver_tcp.cpp: QSettings settings(QLatin1String("Trolltech"), QLatin1String("Qt"));
network/socket/qlocalsocket_tcp.cpp: QSettings settings(QLatin1String("Trolltech"), QLatin1String("Qt"));
plugins/inputmethods/imsw-multi/qmultiinputcontext.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
scripttools/debugging/qscriptenginedebugger.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
scripttools/debugging/qscriptenginedebugger.cpp: QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));