Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT warning level suggestion

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.

like image 903
metdos Avatar asked Apr 30 '10 05:04

metdos


3 Answers

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.

like image 140
photo_tom Avatar answered Oct 29 '22 03:10

photo_tom


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.
like image 20
Jeremy Friesner Avatar answered Oct 29 '22 04:10

Jeremy Friesner


Use CONFIG += warn_on in your .pro file.

See the documentation.

Option

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.
like image 1
doug65536 Avatar answered Oct 29 '22 03:10

doug65536