How to suppress warnings in Qt Creator

大憨熊 提交于 2020-02-01 03:09:46

问题


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!


回答1:


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




回答2:


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




回答3:


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
}
  • http://doc.qt.io/qt-4.8/qmake-advanced-usage.html
  • https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html



回答4:


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



来源:https://stackoverflow.com/questions/9064678/how-to-suppress-warnings-in-qt-creator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!