Results 1 to 4 of 4

Thread: Compiler Warnings from Qt

  1. #1
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default 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
    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,
    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

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. #pragma GCC diagnostic push
    2. #pragma GCC diagnostic ignored "-Wfloat-equal"
    3. // ...
    4. #include <QRect>
    5. // ...
    6. #pragma GCC diagnostic pop
    To copy to clipboard, switch view to plain text mode 

    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.

  3. The following user says thank you to yeye_olive for this useful post:

    sedi (25th November 2015)

  4. #3
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

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

    Qt Code:
    1. QMAKE_CXXFLAGS += -Wall -Wextra -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code
    2. QMAKE_CXXFLAGS += -isystem $$[QT_INSTALL_HEADERS]
    To copy to clipboard, switch view to plain text mode 

    Works like a charm for me.
    Last edited by sedi; 27th December 2015 at 04:42.

  5. #4
    Join Date
    Oct 2015
    Location
    Saint-Petersburg, Russia
    Posts
    10
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default 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

Similar Threads

  1. Replies: 2
    Last Post: 11th March 2014, 13:02
  2. msvc Compiler or mingw compiler
    By Ashutosh2k1 in forum Qt Programming
    Replies: 3
    Last Post: 14th February 2011, 09:33
  3. Replies: 2
    Last Post: 18th November 2010, 09:01
  4. Strange compiler behaviour (compiler passes wrong argument)
    By SasaVilic in forum General Programming
    Replies: 2
    Last Post: 2nd November 2010, 12:36
  5. Where are my compiler warnings?
    By drhex in forum General Programming
    Replies: 5
    Last Post: 18th February 2009, 22:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.