Add function to return an error message for a `QSettings` object
This commit is contained in:
parent
6e52b62706
commit
368c9e9b0e
|
@ -369,6 +369,27 @@ std::unique_ptr<QSettings> getSettings(const QString &organization, const QStrin
|
|||
return settings;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an error message for the specified \a settings or an empty string if there's no error.
|
||||
*/
|
||||
QString errorMessageForSettings(const QSettings &settings)
|
||||
{
|
||||
auto errorMessage = QString();
|
||||
switch (settings.status()) {
|
||||
case QSettings::NoError:
|
||||
return QString();
|
||||
case QSettings::AccessError:
|
||||
errorMessage = QCoreApplication::translate("QtUtilities", "unable to access file");
|
||||
break;
|
||||
case QSettings::FormatError:
|
||||
errorMessage = QCoreApplication::translate("QtUtilities", "file has invalid format");
|
||||
break;
|
||||
default:
|
||||
errorMessage = QCoreApplication::translate("QtUtilities", "unknown error");
|
||||
}
|
||||
return QCoreApplication::translate("QtUtilities", "Unable to sync settings from \"%1\": %2").arg(settings.fileName(), errorMessage);
|
||||
}
|
||||
|
||||
// namespace ApplicationInstances
|
||||
|
||||
} // namespace QtUtilities
|
||||
|
|
|
@ -68,6 +68,7 @@ QT_UTILITIES_EXPORT bool hasCoreApp();
|
|||
|
||||
QT_UTILITIES_EXPORT void setupCommonQtApplicationAttributes();
|
||||
QT_UTILITIES_EXPORT std::unique_ptr<QSettings> getSettings(const QString &organization, const QString &application = QString());
|
||||
QT_UTILITIES_EXPORT QString errorMessageForSettings(const QSettings &settings);
|
||||
|
||||
} // namespace QtUtilities
|
||||
|
||||
|
|
|
@ -25,6 +25,29 @@
|
|||
<translation></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QtUtilities</name>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="382"/>
|
||||
<source>unable to access file</source>
|
||||
<translation>Zugriff auf die Datei ist nicht möglich</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="385"/>
|
||||
<source>file has invalid format</source>
|
||||
<translation>Datei hat ungültiges Format</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="388"/>
|
||||
<source>unknown error</source>
|
||||
<translation>unbekannter Fehler</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="390"/>
|
||||
<source>Unable to sync settings from "%1": %2</source>
|
||||
<translation>Settings können nicht unter "%1" synchronisiert werden: %2</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QtUtilities::AboutDialog</name>
|
||||
<message>
|
||||
|
|
|
@ -25,6 +25,29 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QtUtilities</name>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="382"/>
|
||||
<source>unable to access file</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="385"/>
|
||||
<source>file has invalid format</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="388"/>
|
||||
<source>unknown error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="390"/>
|
||||
<source>Unable to sync settings from "%1": %2</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QtUtilities::AboutDialog</name>
|
||||
<message>
|
||||
|
|
|
@ -25,6 +25,29 @@
|
|||
<translation>Qt</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QtUtilities</name>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="382"/>
|
||||
<source>unable to access file</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="385"/>
|
||||
<source>file has invalid format</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="388"/>
|
||||
<source>unknown error</source>
|
||||
<translation type="unfinished">未知错误</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../resources/resources.cpp" line="390"/>
|
||||
<source>Unable to sync settings from "%1": %2</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QtUtilities::AboutDialog</name>
|
||||
<message>
|
||||
|
|
Loading…
Reference in New Issue