QUdpSocket bind problem
-
@JulsPower
You can try the following code before executing the bind() function#include <winsock2.h> #include <ws2tcpip.h> #pragma comment(lib, "ws2_32.lib") .... WSAData wsadata; int err = WSAStartup(MAKEWORD(2,0), &wsadata); if (err != 0) { qWarning("QTcpSocketAPI: WinSock v2.0 initialization failed."); } ....
-
@JulsPower
You can try the following code before executing the bind() function#include <winsock2.h> #include <ws2tcpip.h> #pragma comment(lib, "ws2_32.lib") .... WSAData wsadata; int err = WSAStartup(MAKEWORD(2,0), &wsadata); if (err != 0) { qWarning("QTcpSocketAPI: WinSock v2.0 initialization failed."); } ....
@Hanson said in QUdpSocket bind problem:
@JulsPower
You can try the following code before executing the bind() function#include <winsock2.h> #include <ws2tcpip.h> #pragma comment(lib, "ws2_32.lib") .... WSAData wsadata; int err = WSAStartup(MAKEWORD(2,0), &wsadata); if (err != 0) { qWarning("QTcpSocketAPI: WinSock v2.0 initialization failed."); } ....
WSAStartup return 0 so no error there
but the bind function continue to return false -
@JulsPower
emmm... I can't figure it out anymore :)
Or you can download the qt source code and debug it. -
@JulsPower
Can you show me where in your code calling WSAGetLastError()? -
@JulsPower
Can you show me where in your code calling WSAGetLastError()?@Hanson said in QUdpSocket bind problem:
@JulsPower
Can you show me where in your code calling WSAGetLastError()?b = m_UdpSocket->bind(QHostAddress::Any, 55555); auto state = m_UdpSocket->state(); QMessageBox::information(this, "info", QString(b?"true ":"false ") + QString::number(state) + QString::number(WSAGetLastError()));
show while debugging it shows false 010106
-
I replicated the samething in a new project using qmake instead of cmake. lo and behold it works in debugging mode...
seem ill be using qmake@JulsPower
Maybe same as this question
https://stackoverflow.com/questions/48597996/qtcpserver-return-unknown-error-on-listen-function-only-under-debugger
https://developercommunity.visualstudio.com/t/native-cmake-support-application-debug-launch-is-b/562174So the reason could be that when debugging the program with cmake project, the environment variables were cleared and the SystemRoot variable was missing, which caused WSASocket to fail to load the related components.
-
-
@JulsPower I understand you probably lack the motivation and time to do it, but it would be interesting to see the differences in the build between cmake generated makefile an qmake generated makfile. Obviously the two are building/linking differently. Smells like a build flag isn't the same in cmake debug