为什么 Qt .pro 文件会为平台提供错误,即使未选择或提及它也是如此?

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

在我的 Qt .pro 文件中,以下给出了 Windows OS 的编译错误:

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

根据qmake tutorial,Windows平台应该绕过上述封锁。然而,即使它不适用,它也会给出错误,因为它正在对 Windows 进行健全性检查。

还有其他这样的例子。
如何修复此类错误?

在这种情况下,问题是由于 Qt QMake 语法引起的。从此linkQMake 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;

语法:

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

.pro 文件更改:

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