From 2d70410009c7472f9f4143a36d19fe929563b9f2 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 11 Nov 2015 16:52:20 +0300 Subject: [PATCH] Correctly detect Qt root directory in the application. --- src/Qtx/Qtx.cxx | 27 +++++++++++++++++++++++++++ src/Qtx/Qtx.h | 2 ++ src/Qtx/QtxResourceMgr.cxx | 7 +------ src/SUITApp/SUITApp.cxx | 8 +++----- src/Session/SALOME_Session_Server.cxx | 8 +++----- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index a4df0a7c3..1a85d9853 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -2069,6 +2069,32 @@ long Qtx::versionToId( const QString& version ) return id; } +/*! + \brief Get Qt installation directory + + The function tries to detect qt installation directory by analyzing the system variables in the following order: + - QT5_ROOT_DIR + - QT4_ROOT_DIR + - QT_ROOT_DIR + - QTDIR + + Optional parameter \a context allows obtaining subdirectory in the Qt installation directory. + + \param context optional sub-directory + \return path to the Qt installation directory (or its sub-folder, if \a context is specified) +*/ + +QString Qtx::qtDir( const QString& context ) +{ + const char* vars[] = { "QT5_ROOT_DIR", "QT4_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" }; + QString qtPath; + for (uint i = 0; i < sizeof(vars)/sizeof(vars[0]) && qtPath.isEmpty(); i++ ) + qtPath = qgetenv( vars[i] ); + if ( !qtPath.isEmpty() && !context.isEmpty() ) + qtPath = QDir( qtPath ).absoluteFilePath( context ); + return qtPath; +} + #ifndef WIN32 #include @@ -2136,4 +2162,5 @@ Qt::HANDLE Qtx::getVisual() return res; } + #endif // WIN32 diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index cf7ba26c4..423735c56 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -260,6 +260,8 @@ public: static long versionToId( const QString& ); + static QString qtDir( const QString& = QString()); + #ifndef WIN32 static void* getDisplay(); static Qt::HANDLE getVisual(); diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 68511cf35..cfb2f523a 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -2697,12 +2697,7 @@ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) if ( pref.isEmpty() && lang != "en" ) { // load Qt resources QString qt_translations = QLibraryInfo::location( QLibraryInfo::TranslationsPath ); - QString qt_dir_trpath = qgetenv( "QT_ROOT_DIR" ); - if ( qt_dir_trpath.isEmpty() ) - qt_dir_trpath = qgetenv( "QTDIR" ); - if ( !qt_dir_trpath.isEmpty() ) - qt_dir_trpath = QDir( qt_dir_trpath ).absoluteFilePath( "translations" ); - + QString qt_dir_trpath = Qtx::qtDir( "translations" ); QTranslator* trans = new QtxTranslator( 0 ); if ( trans->load( QString("qt_%1").arg( lang ), qt_translations ) || trans->load( QString("qt_%1").arg( lang ), qt_dir_trpath ) ) { if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans ); diff --git a/src/SUITApp/SUITApp.cxx b/src/SUITApp/SUITApp.cxx index 9b260f801..0feb3e385 100644 --- a/src/SUITApp/SUITApp.cxx +++ b/src/SUITApp/SUITApp.cxx @@ -177,12 +177,10 @@ int main( int argc, char* argv[] ) } } - // add $QTDIR/plugins to the pluins search path for image plugins - QString qtdir = qgetenv( "QT_ROOT_DIR" ); - if ( qtdir.isEmpty() ) - qtdir = qgetenv( "QTDIR" ); + // add /plugins directory to the pluins search path for image plugins + QString qtdir = Qtx::qtDir( "plugins" ); if ( !qtdir.isEmpty() ) - QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) ); + QApplication::addLibraryPath( qtdir ); //Set a "native" graphic system in case if application runs on the remote host QString remote(::getenv("REMOTEHOST")); diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 7bbb7b274..7e1fbe5f4 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -350,12 +350,10 @@ int main( int argc, char **argv ) QApplication::setGraphicsSystem(QLatin1String("native")); } - // add $QTDIR/plugins to the pluins search path for image plugins - QString qtdir = qgetenv( "QT_ROOT_DIR" ); - if ( qtdir.isEmpty() ) - qtdir = qgetenv( "QTDIR" ); + // add /plugins dir to the pluins search path for image plugins + QString qtdir = Qtx::qtDir( "plugins" ); if ( !qtdir.isEmpty() ) - QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) ); + QApplication::addLibraryPath( qtdir ); // set "C" locale if requested via preferences { -- 2.39.2