Set environment variable ICU_DATA on runtime.

This time before QApplication and manually getting the application dir path.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-11-26 19:56:40 +02:00
parent f81d814bb2
commit 0c78511cfc
4 changed files with 96 additions and 8 deletions

View File

@ -45,6 +45,14 @@ int main(int argc, char *argv[])
QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations
#if defined(APPIMAGE)
/* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
* This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
* to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
*/
VAbstractApplication::SetICUData(argc, argv);
#endif
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
VAbstractApplication::WinAttachConsole(); VAbstractApplication::WinAttachConsole();
#endif #endif

View File

@ -49,6 +49,14 @@ int main(int argc, char *argv[])
QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations
#if defined(APPIMAGE)
/* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
* This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
* to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
*/
VAbstractApplication::SetICUData(argc, argv);
#endif
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
VAbstractApplication::WinAttachConsole(); VAbstractApplication::WinAttachConsole();
#endif #endif

View File

@ -40,10 +40,77 @@
#include <Qt> #include <Qt>
#include <QtDebug> #include <QtDebug>
#include <QWidget> #include <QWidget>
#include <QStandardPaths>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/customevents.h" #include "../vmisc/customevents.h"
#ifdef Q_OS_UNIX
# include <unistd.h>
#endif
namespace
{
QString ApplicationFilePath(int &argc, char **argv)
{
if (argc)
{
static QByteArray procName = QByteArray(argv[0]);
if (procName != argv[0])
{
procName = QByteArray(argv[0]);
}
}
#if defined( Q_OS_UNIX )
# if defined(Q_OS_LINUX) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_EMBEDDED))
// Try looking for a /proc/<pid>/exe symlink first which points to
// the absolute path of the executable
QFileInfo pfi(QStringLiteral("/proc/%1/exe").arg(getpid()));
if (pfi.exists() && pfi.isSymLink())
{
return pfi.canonicalFilePath();
}
# endif
if (argc > 0)
{
QString argv0 = QFile::decodeName(argv[0]);
QString absPath;
if (not argv0.isEmpty() && argv0.at(0) == QLatin1Char('/'))
{
/*
If argv0 starts with a slash, it is already an absolute
file path.
*/
absPath = argv0;
}
else if (argv0.contains(QLatin1Char('/')))
{
/*
If argv0 contains one or more slashes, it is a file path
relative to the current directory.
*/
absPath = QDir::current().absoluteFilePath(argv0);
}
else
{
/*
Otherwise, the file path has to be determined using the
PATH environment variable.
*/
absPath = QStandardPaths::findExecutable(argv0);
}
absPath = QDir::cleanPath(absPath);
QFileInfo fi(absPath);
if (fi.exists())
{
return fi.canonicalFilePath();
}
}
#endif
return QString();
}
}
const QString VAbstractApplication::patternMessageSignature = QStringLiteral("[PATTERN MESSAGE]"); const QString VAbstractApplication::patternMessageSignature = QStringLiteral("[PATTERN MESSAGE]");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -68,14 +135,6 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
openingPattern(false), openingPattern(false),
mode(Draw::Calculation) mode(Draw::Calculation)
{ {
#if defined(APPIMAGE)
/* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
* This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
* to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
*/
qputenv("ICU_DATA", QString(QCoreApplication::applicationDirPath() + QStringLiteral("/../share/icu")).toUtf8());
#endif
QString rules; QString rules;
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 1) #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 1)
@ -281,6 +340,17 @@ bool VAbstractApplication::IsPatternMessage(const QString &message) const
return VAbstractApplication::ClearMessage(message).startsWith(patternMessageSignature); return VAbstractApplication::ClearMessage(message).startsWith(patternMessageSignature);
} }
//---------------------------------------------------------------------------------------------------------------------
void VAbstractApplication::SetICUData(int &argc, char **argv)
{
/* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
* This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
* to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
*/
const QString appDirPath = QFileInfo(ApplicationFilePath(argc, argv)).path();
qputenv("ICU_DATA", QString(appDirPath + QStringLiteral("/../share/icu")).toUtf8());
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
void VAbstractApplication::WinAttachConsole() void VAbstractApplication::WinAttachConsole()

View File

@ -129,6 +129,8 @@ public:
static const QString patternMessageSignature; static const QString patternMessageSignature;
bool IsPatternMessage(const QString &message) const; bool IsPatternMessage(const QString &message) const;
static void SetICUData(int &argc, char ** argv);
protected: protected:
QUndoStack *undoStack; QUndoStack *undoStack;