Details
-
Suggestion
-
Resolution: Unresolved
-
P4: Low
-
None
-
None
-
None
Description
In QTBUG-63076, it has been already suggested by iamsergio to add a QUrl parameterized constructor to QFile. While I understand the reasons given thiago why they don't want this constructor to be added to QFile, I agree with iamsergio that more dev support would be helpful here. Why not add some conversion helpers to Qt? Sth. along the lines of
inline QUrl urlFromLocalPath(QString path) { auto scheme = QStringLiteral("file"); if (!path.isEmpty() && path.at(0) == ':') { path.remove(0, 1); scheme = QStringLiteral("qrc"); } QUrl url = QUrl::fromLocalFile(path); url.setScheme(scheme); return url; } inline QString localUrlToFilePath(QUrl url) { QString path = url.scheme() == QLatin1String("qrc") ? url.path() : url.toLocalFile(); Q_ASSERT_X(url.scheme() == QLatin1String("qrc") || url.scheme() == QLatin1String("file"), "localUrlToFilePath", "url conversion to paths only makes sense for local file or qrc urls"); if (url.scheme() == QLatin1String("qrc")) { path.prepend(':'); } return path; }
Attachments
Issue Links
- relates to
-
QTBUG-103246 Qt should have a QIo like what KIO is. But much much better
- Open
-
QTBUG-83987 Qt on android needs a built-in way to convert Android URIs to real paths
- Closed
- resulted from
-
QTBUG-63076 Introduce QFile(QUrl) constructor
- Closed
Gerrit Reviews
For Gerrit Dashboard: QTBUG-84572 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
523092,2 | Add QUrl::isResource() and QUrl::toLocalFileOrResource() | dev | qt/qtbase | Status: NEW | -1 | 0 |