[Qt-interest] Detecting GUI when compiling

Nikos Chantziaras realnc at arcor.de
Fri Aug 19 15:05:49 CEST 2011


On 08/18/2011 11:50 PM, Alex Strickland wrote:
> Hi
>
> I wish to conditionally compile code depending on whether the
> application has a GUI or not (for testing). Is there a recommended way
> to detect this?

Can you elaborate?  What do you mean with "has a GUI"?  As I understand 
it, you want to have an application that can be built with or without a 
GUI.  Is that correct?  If so, then you provide an option for selecting 
how to build the app in your project file:

   nogui {
       DEFINES += NOGUI
   }

This will define NOGUI which you can check in your code with an #ifdef. 
  To build the application with it defined, you call qmake like this:

   qmake CONFIG+=nogui myapp.pro



More information about the Qt-interest-old mailing list