When I rename a file QFile do not open it
-
Hi,
in my application I read a file in this way:@ QString pathFile = QString::fromWCharArray(p.c_str());
// Open the XML file QFile file(pathFile); // If we can't open the file if (!file.open(QIODevice::ReadOnly)){ throw MyExceptions(L"Can't open the file " + p); return false; } // If we can't set the XML file to the DOM object if (!doc.setContent(&file)) { file.close(); throw MyExceptions(L"Can't set the XML file to the DOM object for file " + p); return false; } file.close(); return true;@
it opens any files, but if I rename one of them, rerun the application and open the file I have just renamed, it show this message error:
Can't open the file bla/bla/blawhat happen??
-
can you check what is the result of QFile::exists() method?
-
You might want to make sure pathFile is the renamed file you are expecting. Like kolegs said, also run a file.exists() on it to see if it is even there.
Renaming the file outside the application shouldn't have any affect on opening it inside the app as long as pathFile points to the correct file.
-
The result is 1 when opening the original file while 0 when I rename it...
-
For both before the rename and after what are the values of pathFile and file.fileName()?
What is the original name of the file and the renamed name?