[Qt-creator] QDir::currentPath() different when run from QtCreator?

Liam Staskawicz liam at makingthings.com
Tue Jun 16 18:55:22 CEST 2009


On Jun 16, 2009, at 2:37 AM, Eike Ziller wrote:

> Hi,
>
> On Jun 15, 2009, at 8:44 PM, ext Liam Staskawicz wrote:
>
>> Hiya - I'm finding that when I run my app on OS X from within
>> QtCreator, the QDir::currentPath() is set as the path of the
>> executable all the way down in the application bundle (myproject.app/
>> Contents/MacOS/myproject) whereas when the project is run normally
>> (just double clicked) the currentPath() is set to the top level
>> bundle location.
>>
>> Is it recommended to simply make some affordances in my code to
>> account for whether it's being run in QtCreator, or is there some
>> other way to resolve this?
>
> You can set the working directory (i.e. currentPath()) to use when
> running from Qt Creator in the Projects mode, Run Settings, Working
> Directory. But it might be even better to avoid usage of
> QDir::currentPath() in your situation completely, e.g. by using
> QCoreApplication::applicationDirPath(), which always points to
> myproject.app/Contents/MacOS, so you can be sure that
> QCoreApplication::applicationDirPath() + "/../../.." points to the
> location where the app bundle is located.
>
> Regards, Eike

Thanks Eike - I was not familiar with  
QCoreApplication::applicationDirPath().  That does seem like the most  
universal solution.

Cheers,
Liam



More information about the Qt-creator-old mailing list