Android: QFileDialog check isLocalFile() with static functions
The functions below try to return the selected QUrl string with toLocalFile(), however in case of Android "content" Uri isLocalFile() is false, thus we end up with empty path. This checks is QUrl isLocalFile() otherwise return QUrl::toString(). * QString QFileDialog::getSaveFileName() * QString QFileDialog::getOpenFileName() * QStringList QFileDialog::getOpenFileNames() * QString QFileDialog::getExistingDirectory() Change-Id: If7eefb3a067d4bd09849807e60554e0ded507f19 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
3dd5caaaec
commit
1576f81baa
@ -2193,8 +2193,12 @@ QString QFileDialog::getOpenFileName(QWidget *parent,
|
||||
Options options)
|
||||
{
|
||||
const QStringList schemes = QStringList(QStringLiteral("file"));
|
||||
const QUrl selectedUrl = getOpenFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes);
|
||||
return selectedUrl.toLocalFile();
|
||||
const QUrl selectedUrl = getOpenFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter,
|
||||
selectedFilter, options, schemes);
|
||||
if (selectedUrl.isLocalFile() || selectedUrl.isEmpty())
|
||||
return selectedUrl.toLocalFile();
|
||||
else
|
||||
return selectedUrl.toString();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2303,11 +2307,16 @@ QStringList QFileDialog::getOpenFileNames(QWidget *parent,
|
||||
Options options)
|
||||
{
|
||||
const QStringList schemes = QStringList(QStringLiteral("file"));
|
||||
const QList<QUrl> selectedUrls = getOpenFileUrls(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes);
|
||||
const QList<QUrl> selectedUrls = getOpenFileUrls(parent, caption, QUrl::fromLocalFile(dir),
|
||||
filter, selectedFilter, options, schemes);
|
||||
QStringList fileNames;
|
||||
fileNames.reserve(selectedUrls.size());
|
||||
for (const QUrl &url : selectedUrls)
|
||||
fileNames << url.toLocalFile();
|
||||
for (const QUrl &url : selectedUrls) {
|
||||
if (url.isLocalFile() || url.isEmpty())
|
||||
fileNames << url.toLocalFile();
|
||||
else
|
||||
fileNames << url.toString();
|
||||
}
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
@ -2549,8 +2558,12 @@ QString QFileDialog::getSaveFileName(QWidget *parent,
|
||||
Options options)
|
||||
{
|
||||
const QStringList schemes = QStringList(QStringLiteral("file"));
|
||||
const QUrl selectedUrl = getSaveFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes);
|
||||
return selectedUrl.toLocalFile();
|
||||
const QUrl selectedUrl = getSaveFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter,
|
||||
selectedFilter, options, schemes);
|
||||
if (selectedUrl.isLocalFile() || selectedUrl.isEmpty())
|
||||
return selectedUrl.toLocalFile();
|
||||
else
|
||||
return selectedUrl.toString();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2657,8 +2670,12 @@ QString QFileDialog::getExistingDirectory(QWidget *parent,
|
||||
Options options)
|
||||
{
|
||||
const QStringList schemes = QStringList(QStringLiteral("file"));
|
||||
const QUrl selectedUrl = getExistingDirectoryUrl(parent, caption, QUrl::fromLocalFile(dir), options, schemes);
|
||||
return selectedUrl.toLocalFile();
|
||||
const QUrl selectedUrl =
|
||||
getExistingDirectoryUrl(parent, caption, QUrl::fromLocalFile(dir), options, schemes);
|
||||
if (selectedUrl.isLocalFile() || selectedUrl.isEmpty())
|
||||
return selectedUrl.toLocalFile();
|
||||
else
|
||||
return selectedUrl.toString();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user