summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2012-07-15 21:58:59 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-14 23:44:15 +0100
commit6b9545a980f09d8fb034d930cfe67f6110357d0c (patch)
tree64e06f5035a9f6f0fe6e19388710b52cdbbb0f83 /src/corelib
parent327b2ba3b77e7a738ccfbe84c6ca5e9525010630 (diff)
QUrl: methods for converting QStringList <-> QList<QUrl>
This is a very common thing to do, e.g. in order to send urls via DBus. Change-Id: I277902460ee1ad6780446e862e86b3c2eb8c5315 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qurl.cpp31
-rw-r--r--src/corelib/io/qurl.h3
2 files changed, 34 insertions, 0 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 2a439b3a7c..22a0cfdbae 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -3765,6 +3765,37 @@ QString QUrl::errorString() const
}
/*!
+ \since 5.1
+
+ Converts a list of \a urls into a list of QStrings, using toString(\a options).
+*/
+QStringList QUrl::toStringList(const QList<QUrl> &urls, FormattingOptions options)
+{
+ QStringList lst;
+ lst.reserve(urls.size());
+ foreach (const QUrl &url, urls)
+ lst.append(url.toString(options));
+ return lst;
+
+}
+
+/*!
+ \since 5.1
+
+ Converts a list of strings representing \a urls into a list of urls, using QUrl(str, \a mode).
+ Note that this means all strings must be urls, not for instance local paths.
+*/
+QList<QUrl> QUrl::fromStringList(const QStringList &urls, ParsingMode mode)
+{
+ QList<QUrl> lst;
+ lst.reserve(urls.size());
+ foreach (const QString &str, urls) {
+ lst.append(QUrl(str, mode));
+ }
+ return lst;
+}
+
+/*!
\typedef QUrl::DataPtr
\internal
*/
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index c45708cc1a..a9bedb77c3 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -322,6 +322,9 @@ public:
static QString fromAce(const QByteArray &);
static QByteArray toAce(const QString &);
static QStringList idnWhitelist();
+ static QStringList toStringList(const QList<QUrl> &uris, FormattingOptions options = FormattingOptions(PrettyDecoded));
+ static QList<QUrl> fromStringList(const QStringList &uris, ParsingMode mode = TolerantMode);
+
static void setIdnWhitelist(const QStringList &);
friend Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed = 0) Q_DECL_NOTHROW;