Qt バグ レポートへのリンク: QTBUG-53313
Qt 5.5 から Qt 5.6 に移行すると、システム スコープで QSettings 構成ファイルが見つからないというQSettingsの問題が発生します。以下の main.cpp では、QSettings がさまざまな方法で初期化され、そのプロパティが照会されます。
// File: main.cpp
#include <QApplication>
#include <QDebug>
#include <QSettings>
#include <QCoreApplication>
#define ASSUMED_SYSTEM_CONFIG "/etc/xdg/TheOrg/TheApp.conf"
#define ASSUMED_USER_CONFIG "/home/user/.config/TheOrg/TheApp.conf"
void print_info(const QSettings& settings, const char& use_case);
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("TheOrg");
QCoreApplication::setApplicationName("TheApp");
QSettings settings_a;
QSettings settings_b("TheOrg", "TheApp");
QSettings settings_c(QSettings::SystemScope, "TheOrg", "TheApp");
QSettings settings_d(QSettings::NativeFormat, QSettings::SystemScope, "TheOrg", "TheApp");
print_info(settings_a, 'a');
print_info(settings_b, 'b');
print_info(settings_c, 'c');
print_info(settings_d, 'd');
return a.exec();
}
void print_info(const QSettings& settings, const char& use_case)
{
int value = settings.value("the_value").toInt();
qDebug() << "Using case (" << use_case << ")";
qDebug() << "The value is " << value;
qDebug() << "Settings scope is: " << ((settings.scope() == QSettings::SystemScope) ? "System" : "User");
qDebug() << "Settings organization is: " << settings.organizationName();
qDebug() << "Settings application name is: " << settings.applicationName();
qDebug() << "Settings fallbackEnabled is: " << settings.fallbacksEnabled();
qDebug() << "Settings filename is: " << settings.fileName() << "\n";
}
ASSUMED_USER_CONFIGファイルがシステムに存在しません。
ASSUMED_SYSTEM_CONFIGファイルはシステム上に存在し、次のものが含まれています。
the_value = 42
Qt 5.5 でコンパイルすると、プログラムは以下を返します。
Using case ( a )
The value is 42
Settings scope is: User
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/home/user/.config/TheOrg/TheApp.conf"
Using case ( b )
The value is 42
Settings scope is: User
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/home/user/.config/TheOrg/TheApp.conf"
Using case ( c )
The value is 42
Settings scope is: System
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/etc/xdg/TheOrg/TheApp.conf"
Using case ( d )
The value is 42
Settings scope is: System
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/etc/xdg/TheOrg/TheApp.conf"
Qt 5.6 でコンパイルすると、プログラムは以下を返します。
Using case ( a )
The value is 0
Settings scope is: User
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/home/user/.config/TheOrg/TheApp.conf"
Using case ( b )
The value is 0
Settings scope is: User
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/home/user/.config/TheOrg/TheApp.conf"
Using case ( c )
The value is 0
Settings scope is: System
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/home/user/Qt5.6/5.6/gcc_64/etc/xdg/TheOrg/TheApp.conf"
Using case ( d )
The value is 0
Settings scope is: System
Settings organization is: "TheOrg"
Settings application name is: "TheApp"
Settings fallbackEnabled is: true
Settings filename is: "/home/user/Qt5.6/5.6/gcc_64/etc/xdg/TheOrg/TheApp.conf"
ここにはいくつかの問題があります。
Qt 5.5 でコンパイルすると、すべてのケース (a、b、c、d) で設定 'filename' が期待どおりに構築されます。ケース「a」および「b」は、ASSUMED_USER_CONFIG ファイルが存在しないため、ASSUMED_SYSTEM_CONFIG ファイルにフォールバックしています。このため、「the_value」は設定ファイルから正しく取得されます。
ただし、Qt 5.6 でコンパイルすると、「c」および「d」の場合、設定「ファイル名」が正しく構築されないようです (正しいパスが「/home/user/Qt5.6/5.6/gcc_64」に追加されます)。 . このため、設定ファイルから「the_value」を取得できません。
Qt Creator のデフォルトの環境変数を上書きしていません。Qt 5.6 は Qt Maintenance ツールによって自動的にインストールされました。環境変数 XDG_CONFIG_HOME を使用して QSettings::SystemScope ファイルへの絶対パスを設定できることは承知していますが、これを行う必要はないと思います。
主な問題をもう一度述べると、QSettings で ASSUMED_SYSTEM_CONFIG ファイル (QSettings::SystemScope) を使用するにはどうすればよいですか?
他の誰かがこれに反対しましたか?これを2台の別々のマシンでテストしました。