QDir::exists() returns false while directory exists
-
Similar issue to that one:
https://forum.qt.io/topic/124795/issues-with-qtdir-existWhile Qt doc says
https://doc.qt.io/qt-6/qdir.html#examples
to check dir existence do:QDir path(myPath); return path.exists() && path.isReadable()
both functions return
false
while dir exists and readable (selected by QMLFolderDialog
). Qt 6.8.2, Ubuntu 22.04. What the problem could be?! Qt bug? How to solve? -
@J-Hilk said in QDir::exists() returns false while directory exists:
Folrderdialog gives you a QUrl not a path that QDir would accept.
How to you convert it ?I have not converted it, thought
QDir
should understandQUrl
. SoQDir::toNativeSeparators(QUrl(myPath).toLocalFile())
works - thanks!@Aleksey_K
No need to callQDir::toNativeSeparators()
here, theQUrl(myPath).toLocalFile()
turns it into a Qt-platform-agnostic/
-type path, which is all Qt file routines are happy dealing with. You only needtoNativeSeparators()
if you need to do something "external" which demands a native, real OS e.g.\
-type path, such as passing it to an OS command or a native OS system call. Just so you know. -
Folrderdialog gives you a QUrl not a path that QDir would accept.
How to you convert it ? -
@J-Hilk said in QDir::exists() returns false while directory exists:
Folrderdialog gives you a QUrl not a path that QDir would accept.
How to you convert it ?I have not converted it, thought
QDir
should understandQUrl
. SoQDir::toNativeSeparators(QUrl(myPath).toLocalFile())
works - thanks! -
-
@J-Hilk said in QDir::exists() returns false while directory exists:
Folrderdialog gives you a QUrl not a path that QDir would accept.
How to you convert it ?I have not converted it, thought
QDir
should understandQUrl
. SoQDir::toNativeSeparators(QUrl(myPath).toLocalFile())
works - thanks!@Aleksey_K
No need to callQDir::toNativeSeparators()
here, theQUrl(myPath).toLocalFile()
turns it into a Qt-platform-agnostic/
-type path, which is all Qt file routines are happy dealing with. You only needtoNativeSeparators()
if you need to do something "external" which demands a native, real OS e.g.\
-type path, such as passing it to an OS command or a native OS system call. Just so you know. -
-
@J-Hilk said in QDir::exists() returns false while directory exists:
Folrderdialog gives you a QUrl not a path that QDir would accept.
How to you convert it ?I have not converted it, thought
QDir
should understandQUrl
. SoQDir::toNativeSeparators(QUrl(myPath).toLocalFile())
works - thanks!@Aleksey_K said in QDir::exists() returns false while directory exists:
thought QDir should understand QUrl.
Where did you read this? A local directory is something totally different than an url...