I compile my Qt5-based project with warnings enabled on g++:
# project.pro file
QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Wconversion -Weffc++
When compiling, Qt produces lots of warnings (1000+ with just one simple widget), hiding the warnings from my code.
How to tell qmake to use the -isystem
switch when specifying the Qt's headers rather than -I
to suppress the warnings? I don't want to turn warnings off I want to keep them for my code.
NOTE: I checked this SO question but it does not work in my case, it might be only for Qt4, I use Qt5.
NOTE 2: this is an acknowledged bug, I am looking for a workaround. I use a recent version of qmake compiled from sources 5.4.1, this version passes system headers from /include
and /usr/include
as system headers but not the Qt's headers.
NOTE 3: I know CMake would work but this is not an option for me.
Best Answer
I found two ways to suppress warnings from Qt's headers, one way by installing Qt in system's path (as suggested in the other answer) and the other directly from your
pro
file by using GCC flags.When building your own Qt, configure the header's installation path to one of your system path:
System paths are
/usr/include
or/usr/local/include
or one of the rest listed in:Source: this thread in Qt's devel list.
Or directly in your Qt
pro
file, simply add the-isystem
flag into theQMAKE_CXXFLAGS
:The resulting GCC command line looks like:
Note how the Qt's include paths are still added with
-I
, allowing Qt Creator to "see" all Qt headers, but GCC sees the-isystem
flag and suppresses warnings for all subfolders.