PDA

View Full Version : Qt Creator Compiler Warnings from Qt



sedi
25th November 2015, 15:14
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

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 (https://bugreports.qt.io/browse/QTBUG-5076) states,
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

yeye_olive
25th November 2015, 16:39
I suppose that the lines generating these warnings are within inline methods of the classes you mention.

Some compilers, such as GCC (https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html) (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:

#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.

sedi
27th December 2015, 03:44
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 (http://comments.gmane.org/gmane.comp.lib.qt.devel/17036), that there seems to be a patch by Thiago:

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.:


QMAKE_DEFAULT_INCDIRS = C:/Qt/5.5/mingw492_32/include/
I've taken theinfo about the folder from the warnings, e.g.:

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 (http://stackoverflow.com/questions/30513594/how-to-include-qts-headers-with-isystem-system-headers-with-qmake-and-qt5):


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.

magrif
10th November 2020, 08:18
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wfloat-equal")

// Some code that throws warnings

QT_WARNING_POP