Compiler Warnings from Qt
Hi,
when building my projects I get flooded with tons of compiler warnings - mostly not from my code, but from Qt itself. Therefore I don't see the important warnings (from my own code).
Most of the warnings are
Quote:
warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
and among the most notorious Qt classes I find
- QRect
- QVector2d
- QVector3d
- QVector4d
- QMatrix4x4
- QQuaternion
As this QtBug states,
Quote:
The code is intentional the way it is.
Can I somehow disable compiler warnings generated by Qt code while keeping maximally paranoid error level for my own works?
It actually renders the very idea of compiler warnings useless, if you drown in warnings you cannot get rid of.
It might perhaps a n00b question, as I didn't find much about this problem on the web and in the Qt Bugtracker, so it apparently is'nt a problem to most people.
My Environment:
- Win7
- Qt Creator 3.5.1,
- Qt 5.4.2
- MinGW 4.9.2 32b
Re: Compiler Warnings from Qt
I suppose that the lines generating these warnings are within inline methods of the classes you mention.
Some compilers, such as GCC (and possibly MinGW), let you temporarily disable certain warnings. You could wrap the lines #including the offending files in a section disabling specific warnings, as in:
Code:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
// ...
#include <QRect>
// ...
#pragma GCC diagnostic pop
Not the most portable solution, I'm afraid, but unless Qt fixes their code (for instance by doing exactly this trick inside their code) I fear you are out of luck.
Re: Compiler Warnings from Qt / QMAKE_DEFAULT_INCDIRS)
Still having the problem, as portability is mandatory here. It happens with a newly set up win7/64bit system as well.
I've found out in this thread, that there seems to be a patch by Thiago:
Quote:
It looks like Thiago Macieira committed a fix for this back in January
(just add paths to QMAKE_DEFAULT_INCDIRS).
I am not sure, if this is an Environment variable or some .pro file setting, in addition I am not sure if the path I suspect is the right one. I've tried this - and some variants (quotes , higher folder levels etc") - in the .pro file.:
Quote:
QMAKE_DEFAULT_INCDIRS = C:/Qt/5.5/mingw492_32/include/
I've taken theinfo about the folder from the warnings, e.g.:
Quote:
C:/Qt/5.5/mingw492_32/include/QtCore/qlist.h:436:13: warning: cannot optimize loop, the loop counter may overflow [-Wunsafe-loop-optimizations]
while (current-- != from)
And I've created an environment variable by that name and content.
Both yet to no avail, warnings are still flushing in from Qt...
------------------------------------------------------------------------
edited:
------------------------------------------------------------------------
Finally I've found the solution here:
Code:
QMAKE_CXXFLAGS += -Wall -Wextra -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code
QMAKE_CXXFLAGS += -isystem $$[QT_INSTALL_HEADERS]
Works like a charm for me.
Re: Compiler Warnings from Qt / QMAKE_DEFAULT_INCDIRS)
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wfloat-equal")
// Some code that throws warnings
QT_WARNING_POP