Search code examples
c++windowsqtcompiler-errorsqmake

Why Qt .pro file gives error for a platform, even when it is not selected or mentioned?


In my Qt .pro file, following gives compilation error with Windows OS:

!win32
{
  QMAKE_CXXFLAGS += -Wno-unused-parameter -Wno-missing-field-initializers -Wimplicit-fallthrough=0
}

According to qmake tutorial, the Windows platform should bypass the above block. Yet, it gives error as of it's doing sanity checking even for Windows, even though it's not applicable.

There are other such examples as well.
How to fix such errors?


Solution

  • In this case issue is coming due to Qt QMake Syntax. From this link QMake Advanced Usage

    Scopes consist of a condition followed by an opening brace on the same line, a sequence of commands and definitions, and a closing brace on a new line. The opening brace must be written on the same line as the condition. Scopes may be concatenated to include more than one condition;

    Syntax:

    <condition> {
      0<command or definition>
    ...
    }
    

    .pro file change:

    !win32 {
    QMAKE_CXXFLAGS += -Wno-unused-parameter -Wno-missing-field-initializers -Wimplicit-fallthrough=0
    }  # compiles fine