Linux 如何在 Qt Creator 中抑制警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9064678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:16:56  来源:igfitidea点击:

How to suppress warnings in Qt Creator

linuxqtg++qt-creatorcompiler-warnings

提问by linello

I'm wondering if it is possible to suppress compiler specific warnings in Qt-Creator.

我想知道是否可以在 Qt-Creator 中抑制编译器特定的警告。

My g++-4.5 prints:

我的 g++-4.5 打印:

warning: enumeral and non-enumeral type in conditional expression

警告:条件表达式中的枚举和非枚举类型

I would like to get rid of it, because it's very annoying.

我想摆脱它,因为它很烦人。

  • Ubuntu 11.04 x64
  • g++-4.5
  • QtCreator 2.01
  • Qt 4.7
  • Ubuntu 11.04 x64
  • 克++-4.5
  • QtCreator 2.01
  • Qt 4.7

Thank you!

谢谢!

回答by Wes Hardaker

You probably have two choices:

你可能有两个选择:

  1. fix the warning itself (the above looks like you probably need a cast)
  2. find the name of the warnings you want to remove issued by g++ and then add them in your .pro file to the CFLAGS with a 'no-' in front. Something like:

    CFLAGS += -Wno-my-super-warning-I-found

  1. 修复警告本身(上面看起来你可能需要一个演员)
  2. 找到您要删除的由 g++ 发出的警告的名称,然后将它们添加到您的 .pro 文件中,并在前面带有“no-”的 CFLAGS。就像是:

    CFLAGS += -Wno-my-super-warning-I-found

回答by Neox

I have looked through gcc warning options. Gcc has option -Wenum-comparewhich is responsible for the warning, however there is no -Wno-enum-compare. The -Wenum-compareoption is most likely set by -Wallunless it is explicitly set. So I would suggest to disable -Wall

我已经查看了 gcc 警告选项。Gcc 有-Wenum-compare负责警告的选项,但是没有-Wno-enum-compare. 除非明确设置-Wenum-compare-Wall否则该选项很可能由设置。所以我建议禁用-Wall

回答by osirisgothra

You need to use this:

你需要使用这个:

QMAKE_CXXFLAGS += -Wno-enum-compare

QMAKE_CXXFLAGS += -Wno-enum-compare

if you get a warning that ends in -Wenum-compare, for example.

例如,如果您收到以-Wenum-compare结尾的警告。

Also, note that some warnings cannot be suppressed as per the GCC documentation take a look at this for ones that you can't suppress, that way you are not given the false idea that your flags aren't working right.

另外,还要注意一些警告无法抑制按照海湾合作委员会的文件 来看看本作的,你无法抑制的,你不给错误的观点那样,你的标志工作不正常。

The best way to know if the flags are being passed to the compiler, obviously, is to look at the compiler output, and make sure your flags are there, you should see -Wno-enum-comparein the command line, for example, even if the flag does not suppress anything. You'd be surprised how hard it can be to find information about stuff like this, it took some digging and I ended up finding it from the auto-complete that works when editing .pro files, if you have problems editing your .pro files, hit Ctrl+Space(or start typing a word and hit Shift+Home), to get a list of valid things you can use in your .pro file just like any other usual source file. It helped me find the right thing (QMAKE_CXXFLAGS, as it turns out, is usually not what people suggest, for some reason)... Oh yeah and this is about Qt version 4.8, creator 2.4, so it may have changed, since this post (they seem to like to do that a lot, i saw the newer versions already have changed drastically).

显然,了解标志是否被传递给编译器的最佳方法是查看编译器输出,并确保您的标志在那里,您应该在命令行中看到-Wno-enum-compare,例如,即使旗帜没有压制任何东西。如果您在编辑 .pro 文件时遇到问题,您会惊讶地发现有关此类内容的信息有多么困难,需要进行一些挖掘,我最终从编辑 .pro 文件时有效的自动完成功能中找到了它,按 Ctrl+Space(或开始输入一个单词并按Shift+Home),以获取您可以在 .pro 文件中使用的有效内容列表,就像任何其他常用源文件一样。它帮助我找到了正确的东西(QMAKE_CXXFLAGS,事实证明,出于某种原因,通常不是人们建议的)......哦,是的,这是关于 Qt 4.8 版,创作者 2.4,所以它可能已经改变,因为这篇文章(他们似乎喜欢这样做很多,我看到较新的版本已经发生了巨大的变化)。

回答by Honest Abe

linux-g++ {
    QMAKE_CXXFLAGS_WARN_ON = -Wall -Wextra -Wno-enum-compare
}

or for any system using g++

或任何使用 g++ 的系统

*-g++ {
    QMAKE_CXXFLAGS_WARN_ON = -Wall -Wextra -Wno-enum-compare
}