I have a Qt application with a large amount of data stored in a folder called "Data", which lies in the same directory as the applications qrc file.
I want to somehow have the application know where to find this folder. I don't want to add all of the data as resource files because I want to be able to add and remove new data files into the Data directory without having to recompile every time. I don't want to hardcode relative file paths because the execution directory can differ depending on operating system, how the application is launched etc, and I don't want to hardcode absolute directories because they won't be the same if the application is compiled on different machines.
How can I make my application know where to look for the data folder? The directory structure of the entire project will be the same regardless of what OS/machine it is on.
The application directory is available through QCoreApplication.applicationDirPath(), available via the global qApp
:
#include <QApplication>
...
QString appDir = qApp.applicationDirPath();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With