Excerpt from AddEditEmployerView.qml...
FileDialog {
id: fileDialog
title: qsTr("Please choose a file")
folder: employersController.picturesLocation()
selectExisting: true
onAccepted: {
image.source = fileDialog.fileUrl
close()
}
onRejected: close()
}
FileDialog {
id: fileDialog
title: qsTr("Please choose a file")
folder: employersController.picturesLocation()
selectExisting: true
onAccepted: {
image.source = fileDialog.fileUrl
close()
}
onRejected: close()
}
To copy to clipboard, switch view to plain text mode
...and from EmployersController.h:
Q_INVOKABLE
QUrl picturesLocation
() { QUrl url
("file:///" + QStandardPaths
::standardLocations(QStandardPaths
::PicturesLocation).
at(0));
if (url.isEmpty())
qDebug() << "Empty url!";
else if (!url.isValid())
qDebug() << "Invalid url!";
else
qDebug() << url;
return url;
}
Q_INVOKABLE QUrl picturesLocation() {
QUrl url("file:///" + QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).at(0));
if (url.isEmpty())
qDebug() << "Empty url!";
else if (!url.isValid())
qDebug() << "Invalid url!";
else
qDebug() << url;
return url;
}
To copy to clipboard, switch view to plain text mode
Fairly straight-forward, right? This prints
QUrl( "file:///C:/Users/MyAccount/Pictures" )
but then I see the following:
QWindowsNativeFileDialogBase::shellItem: SHCreateItemFromParsingName(/C:/Users/My Account/Pictures)) failed ()
As a point of interest, I am in fact opening to the Pictures Location for some reason, but if I change the location type to, for example, Documents Location and rebuild, the dialog continues to open to Pictures Location...and the error message persists but with the documents url instead. This leads me to believe that it is something to do with the url?
The documentation of QML's url type says that,
"When integrating with C++, note that any QUrl value passed into QML from C++ is automatically converted into a url value, and vice-versa."
but I'm not sure where I'm going wrong.
Any insight is appreciated. Thanks!
Bookmarks