QCustomPlot Discussion and Comments

compatibility of winsock2.h with QCustomPlotReturn to overview

I my QT application I am using some legacy code for sending and receiving UDP packets. If I include both the header files <winsock2.h> and the <qcustomplot.h> I get a ton of Winsock redefinition errors.

I traced down the problem to the statement
# include <QtPrintSupport>
in the qcustomplot.h file. If I comment this statement, the winsock2 redefinitions errors do not occur but then of course I am not able to plot anything.

I am doing the usual stuff of adding printsupport in the .pro file.

It seems that the <QtPrintSupport> might be including <windows.h> or <winsock.h> which can cause errors as mentioned in the following

http://www.zachburlingame.com/2011/05/resolving-redefinition-errors-betwen-ws2def-h-and-winsock-h/

I am not sure how to resolve this if I include "qcustomplot.h".
Please let me know if anyone has encountered something similar.

From the QCustomPlot side there aren't any winsock2.h incompatibilities. Sounds like a Qt related thing.

If indeed QtPrintSupport is the problem, you can simply solve it by removing printsupport and commenting out the QCustomPlot::savePdf method. This way you might not clash with winsocks2 (but you'll lose PDF export of plots).

Thanks....that did solve the problem

Using vs2017 and QT 5.11.3. I'm using UDP in my app like the OP. For me, it wasn't when I added qcustomplot to my project that the issue occurred, but as soon as the promoted widget was added to my form. The form's class is not using the UDP. There's a redefinition issue between WinSDK 10.0.17763.0\shared\ws2def.h and winsock.h. I removed PrintSupport and also added to qcustomplot.h

#ifndef QT_NO_PRINTER 
#include <QtPrintSupport/QTPrintSupport>
#endif

But I still have the issue.

In the series of legacy classes that had the redefinition error, I revisited the include statements, reordering and eliminating those that were unnecessary. But in the files that contained a included QTcpSocket, I made the following change:

#define _WINSOCKAPI_   // Suppress Winsock 1.0 header file inclusion
#include <QTcpSocket>

This resolved my issue.