[Qt-creator] Determine if started through Qt Creator

Nikos Chantziaras realnc at gmail.com
Sun Mar 6 11:05:47 CET 2016


On 06/03/16 08:47, Walter Stefan wrote:
> Hi,
>
> I would like to determine in my application, if it was started through
> Qt Creator.
>
> My code should behave slightly different between running from Qt-Creator
> (error handling) or started directly from a terminal.
>
> What is the best approach for this?

In the project settings, you can modify the environment. Choose the 
"run" configuration, and just add an environment variable. Name it 
whatever you want, like IN_QTCREATOR.

In your program, just use:

   qEnvironmentVariableIsSet("IN_QTCREATOR");

(http://doc.qt.io/qt-5/qtglobal.html#qEnvironmentVariableIsSet)

to detect if the variable is set. Obviously, it only going to be set if 
you run the program in Creator.





More information about the Qt-creator mailing list