[Solved] Double click does not read ini file
-
Here an extrange problem:
If I run the executable from Qt Creator or console, the ini file is read correctly. But if I run by double click the executable from the folder, it does not.I'm on Linux, KDE.
-
You are probably using a relative path to an INI file and the current working directory of the executable is different in the different environments.
-
Nope sir, I'm using the same path and the problem is in the same environment. It works running from Qt Creator, then I open the folder and give double click on the executable and doesn't read the ini file.
-
But does the executable start with 'double click' properly and it just doesn't read the ini file? In this case I would suggest you to log the ini file's path to a file and check whether the path is correct.
-
Good!, now I cant see:
Running from Qt Creator or console: Path is right
Running by double clicking: Path is /home/user/ini_file
The ini file must be read from the relative path, which is the application's path. How can I solve? :S
-
If you use relative paths it's always relative to the application's working directory. The working directory is by default the one you start the app from. So if you start it from terminal/command line it will be the directory you're in when you issue the 'execute' command.
If you want to use your application's executable path you can get it with QCoreApplication::applicationDirPath()
"If you want to find the directory containing the application's executable, see QCoreApplication::applicationDirPath()"
http://doc.qt.nokia.com/4.7-snapshot/qdir.htmlBut for this you have to know where your executable really is. For example on Windows it's the .exe you execute with a double-click. On the other hand on Mac the executable is not the .app what users consider as the executable, but the real executable somewhere in the .app
It's a consistent solution but you have to know these differences between the operating systems - if you plan to distribute to multiple operating systems.
-
Excellent!, I just solved this issue using QCoreApplication::applicationDirPath().
Thank you sooo much viktor.benei :)