From 5230d62feb8822743b8204382225485f27bc7b69 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 12 Jun 2012 09:57:10 +0200 Subject: [PATCH] Partial fix for WebKit compilation on Windows qdatetime.h uses std::min/max and on Windows windows.h (or some subsequent header file) may under certain circumstances define min/max as macros. The easiest way to prevent the windows header files from doing that is to define NOMINMAX in the place right before windows.h is included. The other way is to define min and max to min/max themselves to prevent windows.h from doing its evil thing. If a user of Qt (WebKit in this case) chooses the approach of defining min/max to themselves and then includes qdatetime.h, then a subsequent inclusion of windows.h doesn't work because qdatetime.h undefines min/max. We should not enforce the type of workaround needed, therefore this patch removes the workaround from qdatetime.h and requires user code that happens to include windows header files before qdatetime.h (seldom case) to choose either workaround. Change-Id: I7347eec7369491a065e894cff557004e069453d5 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.h | 9 --------- src/network/socket/qnativesocketengine_win.cpp | 3 +++ src/plugins/platforms/windows/accessible/comutils.cpp | 3 +++ tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp | 3 +++ tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp | 2 ++ tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp | 2 ++ tests/benchmarks/corelib/io/qdiriterator/main.cpp | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index af257ea..a648285 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -46,15 +46,6 @@ #include #include -// windows.h defines these identifiers, so undefine it -// ### figure out where in Qt we include it too soon -#ifdef max -# undef max -#endif -#ifdef min -# undef min -#endif - #include QT_BEGIN_HEADER diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index bc26a7f..60c4c73 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -39,6 +39,9 @@ ** ****************************************************************************/ +// Prevent windows system header files from defining min/max as macros. +#define NOMINMAX + #include #include diff --git a/src/plugins/platforms/windows/accessible/comutils.cpp b/src/plugins/platforms/windows/accessible/comutils.cpp index 2823306..05227c9 100644 --- a/src/plugins/platforms/windows/accessible/comutils.cpp +++ b/src/plugins/platforms/windows/accessible/comutils.cpp @@ -38,6 +38,9 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + +#include + #include #include diff --git a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp index fbcaa2c..5285425 100644 --- a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp +++ b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp @@ -50,6 +50,9 @@ # define QT_NO_GETADDRINFO #endif +// To prevent windows system header files from re-defining min/max +#define NOMINMAX + #if defined(Q_OS_WIN) && !defined(QT_NO_GETADDRINFO) # include # include diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp index 1d9ba55..d37f0b7 100644 --- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -40,6 +40,8 @@ ****************************************************************************/ #include +// To prevent windows system header files from re-defining min/max +#define NOMINMAX #if defined(_WIN32) #include #else diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 13c5d96..4caca29 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -41,6 +41,8 @@ #include +// To prevent windows system header files from re-defining min/max +#define NOMINMAX #if defined(_WIN32) #include #else diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp index 758f390..340ed93 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp +++ b/tests/benchmarks/corelib/io/qdiriterator/main.cpp @@ -43,7 +43,7 @@ #include #ifdef Q_OS_WIN -# include +# include #else # include # include -- 2.7.4