Skip to content

Commit 4a3ad4b

Browse files
committed
Update qgis/qt/osg plugin Mac-bundled search paths
- Ensure Qt plugins path is set before Qt references a plugin, e.g. before splash screen - Strip old Mac-native 'find bundle path' code for simple 'if it is there, use it' code based off of QCoreApplication::applicationDirPath()
1 parent 3b4edb8 commit 4a3ad4b

File tree

2 files changed

+33
-54
lines changed

2 files changed

+33
-54
lines changed

src/app/main.cpp

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,36 @@ int main( int argc, char *argv[] )
813813
}
814814
}
815815

816+
// For non static builds on mac and win (static builds are not supported)
817+
// we need to be sure we can find the qt image
818+
// plugins. In mac be sure to look in the
819+
// application bundle...
820+
#ifdef Q_WS_WIN
821+
QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
822+
+ QDir::separator() + "qtplugins" );
823+
#endif
824+
#ifdef Q_OS_MACX
825+
// IMPORTANT: do before Qt uses any plugins, e.g. before loading splash screen
826+
QString myPath( QCoreApplication::applicationDirPath().append( "/../PlugIns" ) );
827+
// Check if it contains a standard Qt-specific plugin subdirectory
828+
if ( !QFile::exists( myPath + "/imageformats" ) )
829+
{
830+
// We are either running from build dir bundle, or launching binary directly.
831+
// Use system Qt plugins, since they are not bundled.
832+
// An app bundled with QGIS_MACAPP_BUNDLE=0 will still have Plugins/qgis in it
833+
myPath = QT_PLUGINS_DIR;
834+
}
835+
836+
// First clear the plugin search paths so we can be sure only plugins we define
837+
// are being used. Note: this strips QgsApplication::pluginPath()
838+
QStringList myPathList;
839+
QCoreApplication::setLibraryPaths( myPathList );
840+
841+
QgsDebugMsg( QString( "Adding Mac QGIS and Qt plugins dirs to search path: %1" ).arg( myPath ) );
842+
QCoreApplication::addLibraryPath( QgsApplication::pluginPath() );
843+
QCoreApplication::addLibraryPath( myPath );
844+
#endif
845+
816846
//set up splash screen
817847
QString mySplashPath( QgsCustomization::instance()->splashPath() );
818848
QPixmap myPixmap( mySplashPath + QString( "splash.png" ) );
@@ -828,58 +858,6 @@ int main( int argc, char *argv[] )
828858
mypSplash->show();
829859
}
830860

831-
// For non static builds on mac and win (static builds are not supported)
832-
// we need to be sure we can find the qt image
833-
// plugins. In mac be sure to look in the
834-
// application bundle...
835-
#ifdef Q_WS_WIN
836-
QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
837-
+ QDir::separator() + "qtplugins" );
838-
#endif
839-
#ifdef Q_OS_MACX
840-
//qDebug("Adding qt image plugins to plugin search path...");
841-
CFURLRef myBundleRef = CFBundleCopyBundleURL( CFBundleGetMainBundle() );
842-
CFStringRef myMacPath = CFURLCopyFileSystemPath( myBundleRef, kCFURLPOSIXPathStyle );
843-
const char *mypPathPtr = CFStringGetCStringPtr( myMacPath, CFStringGetSystemEncoding() );
844-
CFRelease( myBundleRef );
845-
CFRelease( myMacPath );
846-
QString myPath( mypPathPtr );
847-
// if we are not in a bundle assume that the app is built
848-
// as a non bundle app and that image plugins will be
849-
// in system Qt frameworks. If the app is a bundle
850-
// lets try to set the qt plugin search path...
851-
QFileInfo myInfo( myPath );
852-
if ( myInfo.isBundle() )
853-
{
854-
// First clear the plugin search paths so we can be sure
855-
// only plugins from the bundle are being used
856-
QStringList myPathList;
857-
QCoreApplication::setLibraryPaths( myPathList );
858-
// Now set the paths inside the bundle
859-
myPath += "/Contents/Plugins";
860-
QCoreApplication::addLibraryPath( myPath );
861-
if ( QgsApplication::isRunningFromBuildDir() || QGIS_MACAPP_BUNDLE == 0 )
862-
{
863-
QCoreApplication::addLibraryPath( QT_PLUGINS_DIR );
864-
}
865-
//next two lines should not be needed, testing only
866-
#if 0
867-
QCoreApplication::addLibraryPath( myPath + "/imageformats" );
868-
QCoreApplication::addLibraryPath( myPath + "/sqldrivers" );
869-
foreach ( myPath, myApp.libraryPaths() )
870-
{
871-
qDebug( "Path:" + myPath.toLocal8Bit() );
872-
}
873-
qDebug( "Added %s to plugin search path", qPrintable( myPath ) );
874-
QList<QByteArray> myFormats = QImageReader::supportedImageFormats();
875-
for ( int x = 0; x < myFormats.count(); ++x )
876-
{
877-
qDebug( "Format: " + myFormats[x] );
878-
}
879-
#endif
880-
}
881-
#endif
882-
883861
QgisApp *qgis = new QgisApp( mypSplash, myRestorePlugins ); // "QgisApp" used to find canonical instance
884862
qgis->setObjectName( "QgisApp" );
885863

src/plugins/globe/globe_plugin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
111111
{
112112
// OSG_PLUGINS_PATH value set by CMake option
113113
QString ogsPlugins( OSG_PLUGINS_PATH );
114-
if ( QGIS_MACAPP_BUNDLE > 0 && !QgsApplication::isRunningFromBuildDir() )
114+
QString bundlePlugins = QgsApplication::pluginPath() + "/../osgPlugins";
115+
if ( QFile::exists( bundlePlugins ) )
115116
{
116117
// add internal osg plugin path if bundled osg
117-
ogsPlugins = QgsApplication::pluginPath() + "/../osgPlugins";
118+
ogsPlugins = bundlePlugins;
118119
}
119120
if ( QFile::exists( ogsPlugins ) )
120121
{

0 commit comments

Comments
 (0)