Skip to content

Commit

Permalink
Update qgis/qt/osg plugin Mac-bundled search paths
Browse files Browse the repository at this point in the history
- 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()
  • Loading branch information
dakcarto committed Mar 2, 2014
1 parent 3b4edb8 commit 4a3ad4b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 54 deletions.
82 changes: 30 additions & 52 deletions src/app/main.cpp
Expand Up @@ -813,6 +813,36 @@ int main( int argc, char *argv[] )
}
}

// For non static builds on mac and win (static builds are not supported)
// we need to be sure we can find the qt image
// plugins. In mac be sure to look in the
// application bundle...
#ifdef Q_WS_WIN
QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
+ QDir::separator() + "qtplugins" );
#endif

This comment has been minimized.

Copy link
@dakcarto

dakcarto Mar 3, 2014

Author Member

@jef-n While fixing this issue, I moved the whole QCoreApplication::addLibraryPath block (including bit for Windows) to before the splash screen setup. Is this cool for Windows builds?

It seems that the splash setup causes the Qt plugins to be loaded. So, to me, it makes sense that regardless of platform, QApplication should have any custom Qt plugins path added before then. Certainly fixes a longstanding issue we had on Mac that I could not quite figure out before.

#ifdef Q_OS_MACX
// IMPORTANT: do before Qt uses any plugins, e.g. before loading splash screen
QString myPath( QCoreApplication::applicationDirPath().append( "/../PlugIns" ) );
// Check if it contains a standard Qt-specific plugin subdirectory
if ( !QFile::exists( myPath + "/imageformats" ) )
{
// We are either running from build dir bundle, or launching binary directly.
// Use system Qt plugins, since they are not bundled.
// An app bundled with QGIS_MACAPP_BUNDLE=0 will still have Plugins/qgis in it
myPath = QT_PLUGINS_DIR;
}

// First clear the plugin search paths so we can be sure only plugins we define
// are being used. Note: this strips QgsApplication::pluginPath()
QStringList myPathList;
QCoreApplication::setLibraryPaths( myPathList );

QgsDebugMsg( QString( "Adding Mac QGIS and Qt plugins dirs to search path: %1" ).arg( myPath ) );
QCoreApplication::addLibraryPath( QgsApplication::pluginPath() );
QCoreApplication::addLibraryPath( myPath );
#endif

//set up splash screen
QString mySplashPath( QgsCustomization::instance()->splashPath() );
QPixmap myPixmap( mySplashPath + QString( "splash.png" ) );
Expand All @@ -828,58 +858,6 @@ int main( int argc, char *argv[] )
mypSplash->show();
}

// For non static builds on mac and win (static builds are not supported)
// we need to be sure we can find the qt image
// plugins. In mac be sure to look in the
// application bundle...
#ifdef Q_WS_WIN
QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
+ QDir::separator() + "qtplugins" );
#endif
#ifdef Q_OS_MACX
//qDebug("Adding qt image plugins to plugin search path...");
CFURLRef myBundleRef = CFBundleCopyBundleURL( CFBundleGetMainBundle() );
CFStringRef myMacPath = CFURLCopyFileSystemPath( myBundleRef, kCFURLPOSIXPathStyle );
const char *mypPathPtr = CFStringGetCStringPtr( myMacPath, CFStringGetSystemEncoding() );
CFRelease( myBundleRef );
CFRelease( myMacPath );
QString myPath( mypPathPtr );
// if we are not in a bundle assume that the app is built
// as a non bundle app and that image plugins will be
// in system Qt frameworks. If the app is a bundle
// lets try to set the qt plugin search path...
QFileInfo myInfo( myPath );
if ( myInfo.isBundle() )
{
// First clear the plugin search paths so we can be sure
// only plugins from the bundle are being used
QStringList myPathList;
QCoreApplication::setLibraryPaths( myPathList );
// Now set the paths inside the bundle
myPath += "/Contents/Plugins";
QCoreApplication::addLibraryPath( myPath );
if ( QgsApplication::isRunningFromBuildDir() || QGIS_MACAPP_BUNDLE == 0 )
{
QCoreApplication::addLibraryPath( QT_PLUGINS_DIR );
}
//next two lines should not be needed, testing only
#if 0
QCoreApplication::addLibraryPath( myPath + "/imageformats" );
QCoreApplication::addLibraryPath( myPath + "/sqldrivers" );
foreach ( myPath, myApp.libraryPaths() )
{
qDebug( "Path:" + myPath.toLocal8Bit() );
}
qDebug( "Added %s to plugin search path", qPrintable( myPath ) );
QList<QByteArray> myFormats = QImageReader::supportedImageFormats();
for ( int x = 0; x < myFormats.count(); ++x )
{
qDebug( "Format: " + myFormats[x] );
}
#endif
}
#endif

QgisApp *qgis = new QgisApp( mypSplash, myRestorePlugins ); // "QgisApp" used to find canonical instance
qgis->setObjectName( "QgisApp" );

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -111,10 +111,11 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
{
// OSG_PLUGINS_PATH value set by CMake option
QString ogsPlugins( OSG_PLUGINS_PATH );
if ( QGIS_MACAPP_BUNDLE > 0 && !QgsApplication::isRunningFromBuildDir() )
QString bundlePlugins = QgsApplication::pluginPath() + "/../osgPlugins";
if ( QFile::exists( bundlePlugins ) )
{
// add internal osg plugin path if bundled osg
ogsPlugins = QgsApplication::pluginPath() + "/../osgPlugins";
ogsPlugins = bundlePlugins;
}
if ( QFile::exists( ogsPlugins ) )
{
Expand Down

0 comments on commit 4a3ad4b

Please sign in to comment.