编译QT项目时使用的警告级别是多少?QT警告级别暗示
当我和W4编译,我得到了很多的警告,如:
C4127: conditional expression is constant
我应该编译在W3,或寻找其他方式来处理在W4警告,如:添加新头文件和使用编译指示(这里提到的C++编码标准:101规则,指南和最佳实践)。
你的做法是什么?
谢谢。
编译QT项目时使用的警告级别是多少?QT警告级别暗示
当我和W4编译,我得到了很多的警告,如:
C4127: conditional expression is constant
我应该编译在W3,或寻找其他方式来处理在W4警告,如:添加新头文件和使用编译指示(这里提到的C++编码标准:101规则,指南和最佳实践)。
你的做法是什么?
谢谢。
我遇到了完全一样的问题,你有一对夫妇几年前,编译器设置为4级警告抓住尽可能多的潜在问题。当时,我与Qt签有支持合同,并问他们为什么他们的代码会产生如此多的警告。他们的回应是,他们从不确定他们的代码会在没有任何警告的情况下编译。只有他们的代码才能正确运行。
几个attemps后,我开始周围有杂注来禁用警告Qt的头文件,如下图所示 -
#pragma warning(push,3) // drop compiler to level 3 and save current level
#include <QString>
#include <QVariant>
#include <QStack>
#include <QLabel>
#include <QtGui/QTableWidget>
#pragma warning(pop) // restore compiler warning level
通过做这种方式,你只编译Qt的头文件在较低的警告级别。或者无论它需要什么水平来摆脱警告。您可能有一些个别的警告,仍然显示出来,这样你就可以提高警告级别或禁用各个警告与
#pragma warning(disable: 4700)
一些Boost库文件也有这个问题。
就我个人而言,我只是使用qmake默认生成的Makefiles ......假设我可以相信诺基亚的家伙让它生成Makefile来为当前的构建环境做正确的事情。
我看到QMAKE将采取有关警告一些可选参数,但:
The level of warning information can be fine-tuned to help you find problems in your project file:
-Wall
qmake will report all known warnings.
-Wnone
No warning information will be generated by qmake.
-Wparser
qmake will only generate parser warnings. This will alert you to common pitfalls and potential problems in the parsing of your project files.
-Wlogic
qmake will warn of common pitfalls and potential problems in your project file. For example, qmake will report whether a file is placed into a list of files multiple times, or if a file cannot be found.
如果我没有错,那些警告选项是当您运行qmake生成make文件,而不是在运行生成的生成文件时。 – 2010-04-30 15:15:08
在您的.pro
文件中使用CONFIG += warn_on
。
选项
warn_on The compiler should output as many warnings as possible. This is ignored if warn_off is specified. warn_off The compiler should output as few warnings as possible.
如果您与Q_ASSERT在Visual Studio中的战斗,所有的警告推/流行的东西是行不通的,因为宏到位 “实例”,远远落后于你的标题。 所以我建议重新定义Q_ASSERT:
#ifdef NDEBUG
#undef Q_ASSERT
#define Q_ASSERT(x) __noop
#endif
基于user2846246的回答,我发现,添加在任何一个图书馆使用Qt的伎俩编译早期以下(在我的情况该库使用Visual Studio中的预编译的头文件,所以我刚添加的代码是头文件):
#ifndef _DEBUG
#undef Q_ASSERT
#define Q_ASSERT(x) __noop
#undef Q_ASSERT_X
#define Q_ASSERT_X(cond, where, what) __noop
#endif
,因为我不喜欢丢弃整个图书馆的警戒线这是伟大的。
我不明白为什么一个常量条件表达式应该是一个问题。 – 2010-04-30 06:11:11
海事组织,如果它是不变的,只是你不需要它。 Microsoft解释此警告: http://msdn.microsoft.com/en-us/library/6t66728h%28VS.80%29.aspx – metdos 2010-04-30 06:15:51