Search code examples
qtvisual-c++moc

Qt, MSVC, Suppress compiler warning in a moc_


I've just started using MSVC with Qt. While compiling a moc_, MSCV is generating a warning -

"warning C4251: 'QBasicMutex::d_ptr': class 'QBasicAtomicPointer' needs to have dll-interface to be used by clients of class 'QBasicMutex'

In my own source code I can use :-

  #pragma warning ( push )
  #pragma warning ( disable : 4251 )
  #include <QApplication>
  #pragma warning ( pop )

when I include a Qt header, which appears to work, but I can't get it to work with a moc_.

How do I:-

  1. Suppress that warning

  2. Or failing that, turn down the general warning level in MSVC so this warning (and unfortunately any others) are suppressed

I'm using Qt 5.15.2, with MSVC 2019

Thanks.


Solution

  • Add '/wd4251' to your compiler flags (qmake: QMAKE_CXX_FLAGS, cmake: target_compile_definitions)