QFile file("test.txt");
if (file.open(QIODevice::ReadOnly)) {
qDebug()<<"You got me.";
}
I am using:
- Qt 4.8.6 with MSVC 2010
- Qt Creator 3.1.1
- Windows 7 (32 bit)
From the above code, if .pro
file has not been changed, the corresponding build directory
for the debug mode:
D:\...\build-Main-MSVC2010-Debug
and the .exe
of the debug mode will be located in
D:\...\build-Main-MSVC2010-Debug\debug
for the release mode:
D:\...\build-Main-MSVC2010-Release
and the .exe
of the release mode will be located in
D:\...\build-Main-MSVC2010-Release\release
[Question]
If I want the release program to read the "test.txt" file, I put the file in the folder
D:\...\build-Main-MSVC2010-Release\release
which makes sense.
But if I want the debug program to read the "test.txt" file, I have to put the file in the folder
D:\...\build-Main-MSVC2010-Debug\
rather than
D:\...\build-Main-MSVC2010-Debug\debug
I am wondering why the relative file path worked differently in debug & release mode, it has been bothering me for a long time.
[Edit]
Thanks for @Paul and @lpapp. Here is the screenshot of working directory:
Debug:
Release:
[Very important Edit]
For @Paul and @lpapp:
I used to copy required .dll
to the release folder to test runtime, and I just found if I execute the release program through Qt Creator, the working directory will work just like what you said. But if I directly click the .exe in the release folder, the situation will be as what I said in the question. I think there might be differences between running program from Qt Creator and directly executing the program.