如何抑制 Qt Creator 中的警告
我想知道是否可以在 Qt-Creator 中抑制编译器特定的警告。
我的 g++-4.5 打印:
警告:条件表达式中的枚举和非枚举类型
我想摆脱它,因为它非常烦人。
- Ubuntu 11.04 x64
- g++-4.5
- QtCreator 2.01
- Qt 4.7
谢谢!
I'm wondering if it is possible to suppress compiler specific warnings in Qt-Creator.
My g++-4.5 prints:
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
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你需要使用这个:
例如,如果您收到以 -Wenum-compare 结尾的警告,则
。另请注意,根据 GCC 文档,某些警告无法被抑制
看看这个,看看那些你无法抑制的,你没有得到的方式
您的标志无法正常工作的错误想法。
显然,了解标志是否传递给编译器的最佳方法是查看编译器输出,并确保您的标志在那里,您应该在中看到 -Wno-enum-compare例如,即使该标志不抑制任何内容,也可以使用命令行。您会惊讶地发现,找到有关此类内容的信息是多么困难,需要进行一些挖掘,如果您在编辑 .pro 文件时遇到问题,我最终会从编辑 .pro 文件时起作用的自动完成功能中找到它,按 Ctrl+Space(或开始输入单词并按 Shift+Home),获取可在 .pro 文件中使用的有效内容列表,就像任何其他内容一样其他常用的源文件。它帮助我找到了正确的东西(QMAKE_CXXFLAGS,事实证明,由于某种原因,通常不是人们建议的那样)...哦,是的,这是关于 Qt 版本 4.8,创建者 2.4,所以自从这篇文章以来,它可能已经改变了(他们似乎很喜欢这样做,我看到新版本已经发生了巨大的变化)。
You need to use this:
if you get a warning that ends in -Wenum-compare, for example.
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-compare in 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).
我已经查看了 gcc 警告选项。 Gcc 有选项
-Wenum-compare
负责发出警告,但是没有-Wno-enum-compare
。除非显式设置,否则-Wenum-compare
选项很可能由-Wall
设置。所以我建议禁用-Wall
I have looked through gcc warning options. Gcc has option
-Wenum-compare
which is responsible for the warning, however there is no-Wno-enum-compare
. The-Wenum-compare
option is most likely set by-Wall
unless it is explicitly set. So I would suggest to disable-Wall
或任何使用 g++ 的系统
or for any system using g++
您可能有两个选择:
找到要删除的 g++ 发出的警告的名称,然后将它们添加到 .pro 文件中的 CFLAGS 中前面有一个“不-”。像这样的东西:
CFLAGS += -Wno-my-super-warning-I-found
You probably have two choices:
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
对于某段代码:
For some piece of code: