October 10, 2011

DSav DSav
Lab Rat
28 posts

[SOLVED] W4 warning level

 

Is there a possibility to run compiler with /W4 option using Qt toolchain (qmake → make)? The following line in project file

  1. QMAKE_CXXFLAGS += /W4

leads to “warning: D9025 : overriding ‘/W4’ with ‘/W3‘” in Build Issues pane.

9 replies

October 10, 2011

Volker Volker
Ant Farmer
5428 posts

Try to change the variable QMAKE_CFLAGS_WARN_ON:

  1. QMAKE_CFLAGS_WARN_ON -= -W3
  2. QMAKE_CFLAGS_WARN_ON += -W4

October 11, 2011

DSav DSav
Lab Rat
28 posts

QMAKE_CFLAGS_WARN_ON switches have no effect, but using

  1. QMAKE_CFLAGS_WARN_ON -= -W3
  2. QMAKE_CFLAGS_WARN_ON += -W4

does enable -W4 for the compiler (MSVC 2010, if it is important); thank you, Volker, for the advice. The problem is, however, that there‘re a lot of warnings coming from the Qt headers (qlist.h, qhash.h, etc). As far as I’m concerned, there’s no way to disable W4 warnings for library headers, but enable them for a project files. Is that true?

October 11, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

In MSVS, you can use #pragma s to specify enable / disable warnings, see MSDN [msdn.microsoft.com]).aspx

  1. #pragma warning(push)
  2. #pragma warning(disable: 4178 3145)
  3.  
  4. // do the masked stuff here
  5.  
  6. #pragma warning(pop)

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

October 11, 2011

DSav DSav
Lab Rat
28 posts

Yeah, I know this. Unfortunately, using pragma’s in every source file of the project is not the solution here.

BTW, the project is actually cross-platform and we use not only MSVC, I was just interested in enabling W4 only on MSVC at this time.

October 12, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

Then I currently can’t help. These templates throw warnings with W4 in MSVC.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

October 12, 2011

DSav DSav
Lab Rat
28 posts

Yes, unfortunately it seems there is currently no possiblilty to find the solution.

I will add [SOLVED] to the title of the thread as I actually received the answer to my question.

April 29, 2012

tiho_d tiho_d
Lab Rat
7 posts

I also compile with warning level 4. Instead of suppressing the warnings with #pragma in every file, I suppressed the Qt generated warnings in general for my projects. The Qt warnings at Warning level 4 with VS 2008 are:

warning C4127: conditional expression is constant
warning C4512: ‘QForeachContainer<T>’ : assignment operator could not be generated
warning C4189: ‘concreteNode’ : local variable is initialized but not referenced

To supress them you can add to your project files:

QMAKE_CXXFLAGS += -wd4127 -wd4512 -wd4189

Thought this might be a good add on to the topic here.

July 16, 2012

genefield genefield
Lab Rat
1 posts

tiho_d wrote:

To supress them you can add to your project files:

QMAKE_CXXFLAGS += -wd4127 -wd4512 -wd4189

What exactly do you mean by project files? The .vcproj files?

If it is, where exactly would “QMAKE_CXXFLAGS += -wd4127 -wd4512 -wd4189” be added?

September 20, 2012

tiho_d tiho_d
Lab Rat
7 posts

genefield: – Sorry for the late reply. QMAKE_CXXFLAGS is a qmake variable so it must be written inside your pro/pri files. As these warnings are VS compiler specific I usually use the following:

  1. win32-msvc2008|win32-msvc2010 {
  2.     # Enable Level 4 compiler warnings
  3.     QMAKE_CXXFLAGS_WARN_ON -= -W3
  4.     QMAKE_CXXFLAGS_WARN_ON += -W4
  5.     # Hush some known Qt warnings
  6.     QMAKE_CXXFLAGS += -wd4127 -wd4512 -wd4189
  7. }

 
  ‹‹ QTCreator(2.3.1) Linux doesn’t show any program output      How to set Visual Studio "Output Directory" : $(OutDir) via *.pro file ››

You must log in to post a reply. Not a member yet? Register here!