Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Where are files typically saved when a relative path is used - Windows and Mac
fs_tigre last edited by
I have a simple question about file location when saved with relative paths. I never thought about this since I have been using absolute paths for most of what I have done until now that I have been working in two different Operating Systems (Windows and Mac) and I'm getting tire of changing paths. I change all of my QFiles to be relative and everything worked fine I just cannot find the files.
Where are files typically saved when a relative path was used?
For instance, where should I expect this file to be saved?
@ QFile file( "sample.txt" );
if ( file.open(QIODevice::WriteOnly | QIODevice::Text)@
Thanks a lot
This will point to your working directory: "QDir::currentPath()":http://qt-project.org/doc/qt-5.1/qtcore/qdir.html#currentPath
The working directory will depend on how are you starting the app and it can vary from the executable location, a shortcut location to an arbitrary path if you're starting the app from the command line.
Relative paths are not very manageable because of that and you should think about prepending one of the standard paths like "QCoreApplication::applicationDirPath()":http://qt-project.org/doc/qt-5.1/qtcore/qcoreapplication.html#applicationDirPath or one of the "QStandardPaths::standardLocations(...)":http://qt-project.org/doc/qt-5.1/qtcore/qstandardpaths.html#standardLocations depending on what you want to do exactly.
edit: Also keep in mind that working directory might not be writable, which is usually the case for windows applications installed to "program files" as writing to it requires administrative privilages.
crisdeveloper last edited by
check if the txt files is not saved inside your root folder where your project is located.
i created a simple notepad and the txt files is saved inside the folder of my project.
fs_tigre last edited by
bq. Relative paths are not very manageable because of that and you should think about prepending one of the standard paths like QCoreApplication::applicationDirPath() [qt-project.org] or one of the QStandardPaths::standardLocations [qt-project.org] depending on what you want to do exactly.
I will look into this.
bq. check if the txt files is not saved inside your root folder where your project is located.
No, it is definitely not in the root folder.