Skip to content

Commit e13d159

Browse files
author
timlinux
committedMay 19, 2008
On windows and mac, add the plugins dir to the search path on application start up.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8467 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 25f014e commit e13d159

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
 

‎src/app/main.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <QStyle>
3333
#include <QPlastiqueStyle>
3434
#include <QTranslator>
35+
#include <QImageReader>
3536

3637
#include <iostream>
3738
#include <cstdio>
@@ -501,6 +502,50 @@ int main(int argc, char *argv[])
501502
mypSplash->show();
502503
}
503504

505+
// For non static builds on mac and win (static builds are not supported)
506+
// we need to be sure we can find the qt image
507+
// plugins. In mac be sure to look in the
508+
// application bundle...
509+
#ifdef Q_WS_WIN
510+
QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
511+
+ QDir::separator() + "plugins" );
512+
#endif
513+
#ifdef Q_OS_MACX
514+
//qDebug("Adding qt image plugins to plugin search path...");
515+
CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
516+
CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle);
517+
const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding());
518+
CFRelease(myBundleRef);
519+
CFRelease(myMacPath);
520+
QString myPath(mypPathPtr);
521+
// if we are not in a bundle assume that the app is built
522+
// as a non bundle app and that image plugins will be
523+
// in system Qt frameworks. If the app is a bundle
524+
// lets try to set the qt plugin search path...
525+
QFileInfo myInfo(myPath);
526+
if (myInfo.isBundle())
527+
{
528+
// First clear the plugin search paths so we can be sure
529+
// only plugins from the bundle are being used
530+
QStringList myPathList;
531+
QCoreApplication::setLibraryPaths(myPathList);
532+
// Now set the paths inside the bundle
533+
myPath += "/Contents/plugins";
534+
QCoreApplication::addLibraryPath( myPath );
535+
//next two lines should not be needed, testing only
536+
//QCoreApplication::addLibraryPath( myPath + "/imageformats" );
537+
//QCoreApplication::addLibraryPath( myPath + "/sqldrivers" );
538+
//foreach (myPath, a.libraryPaths())
539+
//{
540+
//qDebug("Path:" + myPath.toLocal8Bit());
541+
//}
542+
//qDebug( "Added %s to plugin search path", qPrintable( myPath ) );
543+
//QList<QByteArray> myFormats = QImageReader::supportedImageFormats();
544+
//for ( int x = 0; x < myFormats.count(); ++x ) {
545+
// qDebug("Format: " + myFormats[x]);
546+
//}
547+
}
548+
#endif
504549

505550

506551

0 commit comments

Comments
 (0)