QTCPSOCKET 客户端已连接 而服务器无响应

Posted on 2018-02-09 11:43  LOMOoO  阅读(429)  评论(0编辑  收藏  举报

最近在使用qt coding一个项目时,使用到了qtcpsocket模块来编写客户端与服务器。在windows平台下还能正常工作,但是在ubuntu平台下,客户端提示已连接时,服务器却没有响应。经过排查,发现是在重写qtcpsocket的incomingConnection函数时出现问题,incomingConnection(int handle),应改为incomingConnection(qintptr handle)。以下是qintptr的官方解释:

Integral type for representing pointers in a signed integer (useful for hashing, etc.).
Typedef for either qint32 or qint64. This type is guaranteed to be the same size as a pointer on all platforms supported by Qt. On a system with 32-bit pointers, qintptr is a typedef for qint32; on a system with 64-bit pointers, qintptr is a typedef for qint64.
Note that qintptr is signed. Use quintptr for unsigned values.