Build errors in qjsnumbercoercion.h under Qt 6.6.0 on Windows 11
-
Hello. I've been in Qt development for a little over two years. This is my first post here.
Our C++ project on Windows 11 builds correctly under Qt 5.15.2 and 6.5.2. I installed Qt 6.6.0 and tried to build. I am getting compiler errors in the Qt header file C:\Qt\6.6.0\msvc2019_64\include\QtQml\qjsnumbercoercion.h. The compiler error appears to be triggered by the file's use of std::numeric_limit, in the function isInteger. This function has been changed in the qjsnumbercoercion.h header file between versions Qt 6.5.2 and 6.6.0.
Here's the 6.5.2 version that builds:
static constexpr bool isInteger(double d) { return equals(d, d) && equals(static_cast<int>(d), d); }
And here's the 6.6.0 version that does not build:
static constexpr bool isInteger(double d) { // Comparing d with itself checks for NaN and comparing d with the min and max values // for int also covers infinities. if (!equals(d, d) || d < std::numeric_limits<int>::min() || d > std::numeric_limits<int>::max()) { return false; } return equals(static_cast<int>(d), d); }
I've added a screenshot from Qt Creator to show the compiler error messages here:
Do I have to change something in the configuration? Thanks.
-
@Escovado It's not a problem with Qt. This error means that your global namespace is polluted with a
min
macro and the compiler tries to expand that macro when it sees "min" instd::numeric_limits<int>::min()
, which is not a macro.Number of libraries do that sadly, the most notorious one on Windows are the windows headers themselves. If you have
windows.h
or other WinAPI headers in your project try to add#define NOMINMAX
before you include them or add that globally to your project. This prevents windows headers from defining these macros. You can add#define WIN32_LEAN_AND_MEAN
while you're at it, which further decreases global scope pollution that windows headers do and shortens compilation times too.If the macro doesn't come from windows headers you'll have to track it down otherwise, but the problem is the global macro, not the code in Qt.
-
Adding the #define NOMINMAX in the source file that loads a lot of header files did the trick. I'll have to track down the specific header that's causing this. You put me on the right track. Thank you.
-