How can I stop warnings about unused private fields?

When compiling a collection of files in a Qt project, I see many warnings similar to this one.

In file included from /usr/local/Trolltech/Qt-4.8.6/include/QtGui/qevent.h:52: /usr/local/Trolltech/Qt-4.8.6/include/QtGui/qmime.h:119:10: warning: private field 'type' is not used [-Wunused-private-field] char type; ^ 

In sentences from different searches, I added an entry

QMAKE_CXXFLAGS + = -Wno-unused-private-field

in the .pro file and confirmed that it displays correctly in compiler calls, but I still get this warning.

I am running Qt on Mac with clang.

Thanks in advance for any ideas.

+4
source share
4 answers

In this answer , try

 QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-private-field 

It seems that the QMAKE_CXXFLAGS_WARN_ON flags QMAKE_CXXFLAGS_WARN_ON added to the compiler command line after QMAKE_CXXFLAGS and will turn on this warning again (since QMAKE_CXXFLAGS contains -Wall ).

+6
source

It sounds strange that you cannot compile it because of the Qt library. Since I am not developing on a Mac, I would check for supported Mac versions / compilers and how to compile on a Mac. After that, if you meet the requirements, I report it as an error.

Another approach (as already reported in this QT-Bug: To #include generates warnings ) is to include pragmas around the warning headers.

  #pragma GCC diagnostic ignored "-Wunused-private-field" #include <QtGui> #pragma GCC diagnostic warning "-Wunused-private-field" 
+1
source

First of all, I'm not sure what his QT error indicates or not, but I found one recent question on the QT forum about the same. Hope it's resolved.

Possible error: warning qmime.h "char not used"

There is one more, Clang 4.2 warns about not used private field QMacMime "

This can help you.

+1
source

I am not a clang guy, but according to http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-in-system-headers you can use the -isystem flag with a directory in which these Qt Headers will handle them, because the system turns on and suppresses warnings for them.

0
source

Source: https://habr.com/ru/post/1493324/


All Articles