如何抑制 Qt Creator 中的警告

发布于 2024-12-31 20:52:38 字数 253 浏览 0 评论 0原文

我想知道是否可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

迷迭香的记忆 2025-01-07 20:52:39

你需要使用这个:

QMAKE_CXXFLAGS += -Wno-enum-compare

例如,如果您收到以 -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:

QMAKE_CXXFLAGS += -Wno-enum-compare

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).

墨落画卷 2025-01-07 20:52:39

我已经查看了 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

挖鼻大婶 2025-01-07 20:52:39
linux-g++ {
    QMAKE_CXXFLAGS_WARN_ON = -Wall -Wextra -Wno-enum-compare
}

或任何使用 g++ 的系统

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

or for any system using g++

*-g++ {
    QMAKE_CXXFLAGS_WARN_ON = -Wall -Wextra -Wno-enum-compare
}
时光病人 2025-01-07 20:52:39

您可能有两个选择:

  1. 修复警告本身(上面看起来您可能需要强制转换)
  2. 找到要删除的 g++ 发出的警告的名称,然后将它们添加到 .pro 文件中的 CFLAGS 中前面有一个“不-”。像这样的东西:

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

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

瑾兮 2025-01-07 20:52:39

对于某段代码:

QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wenum-compare")

// Some code than throwns warnings

QT_WARNING_POP

For some piece of code:

QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wenum-compare")

// Some code than throwns warnings

QT_WARNING_POP
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文