Question to Qt.resolvedUrl () on Windows
- 
wrote on 26 Jan 2019, 20:20 last edited by
Hello,
I've got a model that provides the path of an image file.
Image { id: img y: 0 x: 0 width: 75 height: 75 source: model.fileIsDir ? "qrc:folder.png" : Qt.resolvedUrl(model.filePath) onSourceChanged: { console.log ("Image source", model.filePath) } }The debug window shows:
qml: Image source C:/Users/MyUser/Pictures/IMG_00000001.jpgand
QML Image: Protocol "c" is unknownI don't really understand why but I changed the line that contains Qt.resolvedUrl () to
: Qt.resolvedUrl("file://" + model.filePath)This means:
Image { id: img y: 0 x: 0 width: 75 height: 75 source: model.fileIsDir ? "qrc:folder.png" : Qt.resolvedUrl("file://" + model.filePath) onSourceChanged: { console.log ("Image source", model.filePath) } }Now I receive
QML Image: Cannot open: file://c/Users/MyUser/Pictures/IMG_00000001.jpgwhich makes sense. If I try to open that URL in a browser it won't open it either. There's a colon missing. The URL
file://c:/Users/MyUser/Pictures/IMG_00000001.jpgopens in a browser and displays the picture.
Is Qt.resolvedUrl () not the correct function to call to convert a file system path into a URL?
 - 
wrote on 26 Jan 2019, 20:48 last edited by
I think the issue is with the Image {source: ... } property.
I thought I can easily work around this but it doesn't look like it.This:
QString OneFile::fileURL() const { QString qsURL = "file://" + m_FileInfo.filePath (); return qsURL; }results in the same QML error message:
QML Image: Cannot open: file://c/Users/MyUser/Pictures/IMG_00000001.jpgWhich means that the colon is swalled in QML, somewhere in the Image component.
I also tried this:
QString OneFile::fileURL() const { QString qsURL = m_FileInfo.filePath (); qsURL.replace (":", "%3A"); qsURL = "file://" + qsURL; return qsURL; }This doesn't cause any QML error message. It simply doesn't work. The image is not displayed.
What am I doing wrong?
 - 
wrote on 26 Jan 2019, 21:16 last edited by
Got it ;-)
QString OneFile::fileURL() const { return QUrl::fromLocalFile (m_FileInfo.filePath ()).toString (); }This topic helped me with the solution:
QQuickWidget no such file issue - 
Got it ;-)
QString OneFile::fileURL() const { return QUrl::fromLocalFile (m_FileInfo.filePath ()).toString (); }This topic helped me with the solution:
QQuickWidget no such file issuewrote on 16 Nov 2023, 04:47 last edited by MairtinOnly 4 years late with the response.
Might be a Qt6 thing, but It'sfile:notfile://.Qt.resolvedUrl("file:" + model.filePath)Result:
file:///c:/proj/mypro/.....