Qt Utilities 6.14.3
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
resources.h
Go to the documentation of this file.
1#ifndef APPLICATION_UTILITIES_RESOURCES_H
2#define APPLICATION_UTILITIES_RESOURCES_H
3
4#include "../global.h"
5
6#include <QString>
7#include <QtContainerFwd>
8#include <QtGlobal>
9
10#include <initializer_list>
11#include <memory>
12
13QT_FORWARD_DECLARE_CLASS(QString)
14QT_FORWARD_DECLARE_CLASS(QSettings)
15#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
16QT_FORWARD_DECLARE_CLASS(QStringList)
17#endif
18
25#define SET_QT_DESKTOP_FILE_NAME
26#if defined(Q_OS_LINUX) && defined(qGuiApp) && defined(APP_ID)
27#undef SET_QT_DESKTOP_FILE_NAME
28#define SET_QT_DESKTOP_FILE_NAME QGuiApplication::setDesktopFileName(QStringLiteral(APP_ID));
29#endif
30
36#define SET_QT_APPLICATION_INFO \
37 QCoreApplication::setOrganizationName(QStringLiteral(APP_AUTHOR)); \
38 QCoreApplication::setOrganizationDomain(QStringLiteral(APP_DOMAIN)); \
39 QCoreApplication::setApplicationName(QStringLiteral(APP_NAME)); \
40 QCoreApplication::setApplicationVersion(QStringLiteral(APP_VERSION)); \
41 SET_QT_DESKTOP_FILE_NAME \
42 ::QtUtilities::setupCommonQtApplicationAttributes()
43
47#define LOAD_QT_TRANSLATIONS \
48 QtUtilities::TranslationFiles::loadQtTranslationFile(QT_TRANSLATION_FILES); \
49 QtUtilities::TranslationFiles::loadApplicationTranslationFile(QStringLiteral(PROJECT_CONFIG_NAME), APP_SPECIFIC_QT_TRANSLATION_FILES)
50
51namespace QtUtilities {
52
53namespace QtUtilitiesResources {
54
57} // namespace QtUtilitiesResources
58
59namespace TranslationFiles {
60
62QT_UTILITIES_EXPORT void loadQtTranslationFile(std::initializer_list<QString> repositoryNames);
63QT_UTILITIES_EXPORT void loadQtTranslationFile(std::initializer_list<QString> repositoryNames, const QString &localeName);
64QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const QString &configName, const QString &applicationName);
65QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const QString &configName, const QString &applicationName, const QString &localeName);
66QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const QString &configName, const std::initializer_list<QString> &applicationNames);
68 const QString &configName, const std::initializer_list<QString> &applicationNames, const QString &localeName);
70} // namespace TranslationFiles
71
72namespace ApplicationInstances {
73
74#if defined(QT_UTILITIES_GUI_QTWIDGETS)
75QT_UTILITIES_EXPORT bool hasWidgetsApp();
76#endif
77#if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
78QT_UTILITIES_EXPORT bool hasGuiApp();
79#endif
81} // namespace ApplicationInstances
82
84QT_UTILITIES_EXPORT std::unique_ptr<QSettings> getSettings(const QString &organization, const QString &application = QString());
85QT_UTILITIES_EXPORT QString errorMessageForSettings(const QSettings &settings);
86
87} // namespace QtUtilities
88
89#endif // APPLICATION_UTILITIES_RESOURCES_H
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Definition global.h:14
QT_UTILITIES_EXPORT bool hasCoreApp()
Returns whether a QCoreApplication has been instantiated yet.
QT_UTILITIES_EXPORT void init()
Initiates the resources used and provided by this library.
Definition resources.cpp:51
QT_UTILITIES_EXPORT void cleanup()
Frees the resources used and provided by this library.
Definition resources.cpp:60
QT_UTILITIES_EXPORT void loadQtTranslationFile(std::initializer_list< QString > repositoryNames)
Loads and installs the appropriate Qt translation file for the current locale.
QT_UTILITIES_EXPORT void clearTranslationFiles()
Clears all translation files previously loaded via the load-functions in this namespace.
QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const QString &configName, const QString &applicationName)
Loads and installs the appropriate application translation file for the current locale.
QT_UTILITIES_EXPORT QString & additionalTranslationFilePath()
Allows to set an additional search path for translation files.
Definition resources.cpp:80
QT_UTILITIES_EXPORT std::unique_ptr< QSettings > getSettings(const QString &organization, const QString &application=QString())
Returns the settings object for the specified organization and application.
QT_UTILITIES_EXPORT void setupCommonQtApplicationAttributes()
Sets Qt application attributes which are commonly used within my Qt applications.
QT_UTILITIES_EXPORT QString errorMessageForSettings(const QSettings &settings)
Returns an error message for the specified settings or an empty string if there's no error.