Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

remove qt headers warning with cmake



  • Hello,
    im using cmake and visual studio for my project, but I got warnings from qt headers. For example:
    Warning C4127 conditional expression is constant C:\Qt\5.15.1\msvc2019_64\include\QtCore\qvector.h 796

    Is there a way to use
    find_package(Qt5 COMPONENTS Core Sql REQUIRED)
    and declare them as system headers?


  • Lifetime Qt Champion

    @Mwoua_Leddar said in remove qt headers warning with cmake:

    Is there a way to use
    find_package(Qt5 COMPONENTS Core Sql REQUIRED)
    and declare them as system headers?

    No since MSVC does not (yet) support 'system headers', but at least they found out at the end of 2017 that it's maybe useful: https://devblogs.microsoft.com/cppblog/broken-warnings-theory/
    But as always they decided that it has to be different than the other compilers so ...

    /edit: and looking at the code this warning is really strange when emitted in a template... wonder how the msvc devs would be able to write it without triggering a warning here

    if (QTypeInfo<T>::isComplex) // C4127
      new (d->end()) T(std::move(copy));
    else
      *d->end() = std::move(copy);
    


  • Well, there is no standard way, but at least, with info from your link, I could add
    if ( MSVC )
    add_compile_options(/experimental:external /external:I C:/Qt/5.15.1/msvc2019_64 /external:W0)
    endif()

    So that I dont have warnings from Qt headers anymore.

    It created a lot (really a lot) of warning C4251, but they are usefull warning cause by a dll export of an entire class, which is bad design.


Log in to reply