Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop warnings about unused private fields?

Tags:

c++

macos

clang

qt

While compiling a collection of files in a Qt project, I'm seeing lots of 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;
     ^

Per suggestions from various searches, I did add the entry

QMAKE_CXXFLAGS += -Wno-unused-private-field

to the .pro file and confirmed that it shows up properly in compiler invocations but I'm still getting that warning.

I'm running Qt on a Mac with clang.

Thanks in advance for any insights.

like image 801
David Avatar asked Jul 25 '13 00:07

David


3 Answers

Per this answer, try

QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-private-field

It appears that the QMAKE_CXXFLAGS_WARN_ON flags are added to the compiler command line after QMAKE_CXXFLAGS, and would re-enable that warning (because QMAKE_CXXFLAGS contains -Wall).

like image 64
Richard Smith Avatar answered Nov 18 '22 11:11

Richard Smith


It sounds strange that you can't compile due to Qt library. As I don't develop on Mac, what I would check is for supported Mac versions/compilers and how to compile on Mac. After that, if you fit requirements, I would report this as bug.

  • QT 4.8 Developing on Mac

  • [stackoverflow] How to build qt 5 project on mac

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

 #pragma GCC diagnostic ignored "-Wunused-private-field"
 #include <QtGui>
 #pragma GCC diagnostic warning "-Wunused-private-field"
like image 38
kikeenrique Avatar answered Nov 18 '22 12:11

kikeenrique


First of all I am not sure on points its bug of QT or not but I found one recent question on QT forum about same. I hope it is solved.

Possible bug: qmime.h warning “char type is unused”

There is one more, Clang 4.2 warns about QMacMime unused private field "type"

This may help you.

like image 1
Santosh Dhanawade Avatar answered Nov 18 '22 12:11

Santosh Dhanawade