Skip to content

Commit 4a03bd0

Browse files
author
telwertowski
committedJul 13, 2006
Use QFile::encode to convert a QString containing a filename to a c-string. Mac expects Utf8 and *nix expects local8Bit. QFile will do the right thing for each platform and not mangle Mac non-ASCII filenames.
git-svn-id: http://svn.osgeo.org/qgis/trunk@5589 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent afff4af commit 4a03bd0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed
 

‎src/plugins/georeferencer/qgsimagewarper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <gdalwarper.h>
99
#include <gdal_frmts.h>
1010

11+
#include <QFile>
12+
1113
#include "qgsimagewarper.h"
1214

1315

@@ -19,7 +21,7 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
1921
ResamplingMethod resampling, bool useZeroAsTrans) {
2022
// Open input file
2123
GDALAllRegister();
22-
GDALDataset* hSrcDS = static_cast<GDALDataset*>(GDALOpen((const char*)input,
24+
GDALDataset* hSrcDS = static_cast<GDALDataset*>(GDALOpen(QFile::encodeName(input).constData(),
2325
GA_ReadOnly));
2426
// Setup warp options.
2527
GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();

‎src/raster/qgsrasterlayer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
388388
GDALAllRegister();
389389

390390
//open the file using gdal making sure we have handled locale properly
391-
myDataset = GDALOpen( (const char*)(theFileNameQString.toLocal8Bit().data()), GA_ReadOnly );
391+
myDataset = GDALOpen( QFile::encodeName(theFileNameQString).constData(), GA_ReadOnly );
392392
if( myDataset == NULL )
393393
{
394394
return false;
@@ -489,7 +489,7 @@ QgsRasterLayer::readFile( QString const & fileName )
489489
GDALAllRegister();
490490

491491
//open the dataset making sure we handle char encoding of locale properly
492-
gdalDataset = (GDALDataset *) GDALOpen((const char*)(fileName.toLocal8Bit().data()), GA_ReadOnly);
492+
gdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(fileName).constData(), GA_ReadOnly);
493493

494494
if (gdalDataset == NULL)
495495
{
@@ -4132,7 +4132,7 @@ void QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramidLis
41324132
GDALAllRegister();
41334133
//close the gdal dataset and reopen it in read / write mode
41344134
delete gdalDataset;
4135-
gdalDataset = (GDALDataset *) GDALOpen(dataSource.toLocal8Bit().data(), GA_Update);
4135+
gdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(dataSource).constData(), GA_Update);
41364136

41374137
// if the dataset couldn't be opened in read / write mode, tell the user
41384138
if (!gdalDataset) {
@@ -4145,7 +4145,7 @@ void QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramidLis
41454145
Qt::NoButton,
41464146
Qt::NoButton );
41474147
myMessageBox.exec();
4148-
gdalDataset = (GDALDataset *) GDALOpen(dataSource.toLocal8Bit().data(), GA_ReadOnly);
4148+
gdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(dataSource).constData(), GA_ReadOnly);
41494149
return;
41504150
}
41514151

@@ -4215,7 +4215,7 @@ void QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramidLis
42154215
Qt::NoButton );
42164216
myMessageBox.exec();
42174217
delete gdalDataset;
4218-
gdalDataset = (GDALDataset *) GDALOpen(dataSource.toLocal8Bit().data(), GA_ReadOnly);
4218+
gdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(dataSource).constData(), GA_ReadOnly);
42194219
emit setProgress(0,0);
42204220
return;
42214221
}
@@ -4232,7 +4232,7 @@ void QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramidLis
42324232
QgsDebugMsg("Pyramid overviews built");
42334233
//close the gdal dataset and reopen it in read only mode
42344234
delete gdalDataset;
4235-
gdalDataset = (GDALDataset *) GDALOpen(dataSource.toLocal8Bit().data(), GA_ReadOnly);
4235+
gdalDataset = (GDALDataset *) GDALOpen(QFile::encodeName(dataSource).constData(), GA_ReadOnly);
42364236
emit setProgress(0,0);
42374237
QApplication::restoreOverrideCursor();
42384238
}

0 commit comments

Comments
 (0)
Please sign in to comment.