Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Can not open file With QFile Class.
Gaurav Badgujar last edited by Gaurav Badgujar
If we pass string like "D:\TestFoldler.docx:GauravData:$DATA" then we can write content in File.
QFile file("D:\TestFoldler.docx:GauravData:$DATA" );
with this we can write content in file.
but if we pass string like "\\nas\files\gauravFolder.docx:GauravData:$DATA" its not work.
QFile file("\\nas\files\gauravFolder.docx:GauravData:$DATA" );
with this we can not write content in file. we can not open file.
please Do needful.
in c++ the
\ has a special meaning. its called escaping so to have it in code you must use 2 QFile("D:\\TestFoldler\\GauravData" );
or use the Qt syntax using the other way. ( and just one)
is not a valid filename on windows.
on linux its other way
so make sure path is indeed correct.
VRonin last edited by
to add to @mrjj if you want to use those paths without duplicating or reversing the slashes you can use raw strings:
QFile file(R"(\nas\files\gauravFolder:GauravData:$DATA)" );
@Gaurav-Badgujar You should not use : in paths/file names especially on Windows
but its working on "D:\TestFoldler:GauravData:$DATA"
but this is not working with "\nas\files\gauravFolder:GauravData:$DATA" path.
@Gaurav-Badgujar As others said you should either use
@jsulm used "/" as per above mention comment but still not getting any resolution.
Try to use a full path and see it it works for you.
Its just path issue, i think.
Also again, if on window, the ":" is FORBIDDEN
@Gaurav-Badgujar What about
\\? What exact error do you get (http://doc.qt.io/qt-5/qiodevice.html#errorString)?
And why do you use characters like : and $ ? You should avoid such characters in paths and file names. Especially :
: has a special meaning on Windows. Try to save a file in any Windows program using file name with : You will see it does not work.
VRonin last edited by
Another option, given the name of the first folder is nas i can guess it's a network path, they normally start with 2 slashes, not just 1
m.sue last edited by m.sue
the file names with ":" hide data using ADS (alternate data streams). Strings like ":$DATA" have a special meaning. Normal Explorer and DIR command etc. do not see these files.
So I doubt Qt can open them for reading/writing; native CreateFile should be able to do so.
On the other hand: make sure that the file "c:/nas/files/gauravFolder" already exist when you create the data stream file! Here is some code: https://support.microsoft.com/en-us/kb/105763
Buckwheat last edited by
There are several things wrong with the path but the :$DATA is the biggest hurdle. It is just not allowed on any M$ operating system. Fixing non-existant paths will be easy but if your file name has special meaning then that could be a problem. Now, if the :$DATA represents some bit of data to write into the file name than ok.
The article "Illegal Characters on Various Operating Systems" explains what is legal on most OSes.
@VRonin yes its network path..typo mistake. and it contains two slashes.
:$DATA its not a path we append this string with path.