summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurl.cpp
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2014-07-09 15:03:35 +0200
committerDavid Faure <david.faure@kdab.com>2014-07-26 09:49:33 +0200
commitfd331a5b3a122393cd697a8b856dd52cfd31d698 (patch)
tree8743ce9b26863cbd5091624e8168257e1d7f6f01 /src/corelib/io/qurl.cpp
parent63efdf9851915ce3b81bffe089fcd1995d6750f8 (diff)
QUrl: fromLocalFile(QString()) should lead to an empty URL.
This is much more useful than the URL "file:", it allows to use "empty path" and "empty URL" for the same meaning (e.g. not set). QFileDialog actually uses "file:" though, as the URL for the "My Computer" item in the sidebar. This patch preserves that. [ChangeLog][QtCore][QUrl] QUrl::fromLocalFile now returns an empty URL if the input string is empty. Change-Id: Ib5ce1a3cdf5f229368e5bcd83c62c1d1ac9f8a17 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r--src/corelib/io/qurl.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 58b169e588..51c48b88d7 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -3738,11 +3738,15 @@ bool QUrl::isDetached() const
"//servername/path/to/file.txt". Note that only certain platforms can
actually open this file using QFile::open().
+ An empty \a localFile leads to an empty URL (since Qt 5.4).
+
\sa toLocalFile(), isLocalFile(), QDir::toNativeSeparators()
*/
QUrl QUrl::fromLocalFile(const QString &localFile)
{
QUrl url;
+ if (localFile.isEmpty())
+ return url;
url.setScheme(fileScheme());
QString deslashified = QDir::fromNativeSeparators(localFile);