views:

282

answers:

2

What is the warning level you use while compiling QT projects?

When I compiled with W4, I'm getting a lot of warnings such as:

C4127: conditional expression is constant

Should I compile at W3, or find other ways to handle warnings at W4, such as: adding a new header file and using pragma's(mentioned here C++ Coding Standards: 101 Rules, Guidelines, and Best Practices).

What are your practices?

Thanks.

+1  A: 

Personally I just use the Makefiles that qmake generates by default... on the presumption that I can trust the guys at Nokia to have it generate Makefiles that do the right thing for the current build environment.

I do see that qmake will take some optional arguments regarding warnings, though:

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.
Jeremy Friesner
If I'm not mistaken, those warning options are for when you run qmake to generate the make file, not for when you run the makefile that is generated.
Caleb Huitt - cjhuitt
+1  A: 

I ran into the exact same problem you have a couple of years ago, that of setting the compiler to level 4 warnings to catch as many potiential problems as possible. At the time, I had a support contract with Qt and asked them why their code generated so many warnings. Their response was that they never gaurenteed that their code would compile without any warnings. Only that their code would run correctly.

After several attemps, I started surrounding the Qt header files with pragmas to disable the warnings as shown below -

#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

By doing it this way, you only compile the Qt header files at the lower warning level. Or whatever level it takes to get rid of the warnings. You may have some individual warnings that still show up, so you could raise the warning level or disable individual warnings with

#pragma warning(disable: 4700)

Some Boost library files also have this problem.

photo_tom