Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
Qt Creator 4.2.1
-
None
-
Windows 10 x64
Description
After I upgraded to QtCreator 4.2.1 + Qt 5.8 I noticed none of my projects can load their assets when launched from QtCreator.
The problem lies in QtCreator randomly setting QDir::currentPath() to current user home directory, instead of the application executable directory (previous behaviour).
I did some testing with a blank Qt console application (tried both QMake and QBS), and 2 kits - MSVC201564bit w/ Qt 5.7.1 and Qt 5.8:
#include <QCoreApplication> #include <QDebug> #include <QDir> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qDebug() << QDir::currentPath(); qDebug() << qApp->applicationDirPath(); return 0; }
When launching the application with the first (default) kit, I get the following output:
"C:/Users/Alan"
"E:/Qt_build/DirTestQmake-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug/debug"
On previous QtCreator version I used (4.1), they both pointed to application executable directory.
If the first kit test fails, the second kit usually passes, and it seems it behaves randomly between QtCreator restarts.
The only consistent behaviour I found is:
1. Click Projects
2. Under current kit select Run to open Run settings
3. No need to change anything, just run the application and the output gives expected results:
"E:/Qt_build/DirTestQmake-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug"
"E:/Qt_build/DirTestQmake-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug/debug"
or in case of QBS:
"E:/Qt_build/DirTest-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug/qtc_Desktop__401a3d47-debug/install-root"
"E:/Qt_build/DirTest-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug/qtc_Desktop__401a3d47-debug/install-root"
After restarting QtCreator, the "fix" is gone and requires clicking on the Run tab again to properly set the path.
Another workaround I found is adding the following to every application that relies on current dir, but I would rather prefer for QtCreator to be consistent about it:
QDir::setCurrent(qApp->applicationDirPath());
Attachments
Issue Links
- is duplicated by
-
QTCREATORBUG-17749 Project working directory from run settings initially not applied
- Closed