QAbstractSocket::UnknownSocketError

拥有回忆 提交于 2019-12-20 03:37:06

问题


What could be cause of QAbstractSocket::UnknownSocketError when using QTcpSocket?


CODE

I'm getting this error code with the following code:

this->connect(socket, SIGNAL(socketError(QAbstractSocket::SocketError)), SLOT(handleSocketError(QAbstractSocket::SocketError)));
...
void MyClass::handleSocketError(QAbstractSocket::SocketError error)
{
    qDebug() << error;
}

MORE INFO

The QTcpSocket is trying to connect to some remote host. And it fails with mentioned error code.


回答1:


If you read the code, you'll see that this error means exactly what it says: "something bad happened and I don't know why". There had to be exceptions, of course:

  • The socket is not connected to a server and you try to write to it (src/network/socket/qabstractsocket.cpp on line 2025)
  • An SSL error occurred (src/network/ssl/qsslsocket_openssl.cpp in a lot of places)

In both situations the errorString is set to an appropriate message.




回答2:


Possibly you called the error() function when there is no error.




回答3:


Looking for AbstractSocketError in the Qt sources gives quite some hits. Maybe fire up a debugger and look into the backtrace when you get the error() signal. Possibly an exotic error condition occured in the underlying socket engine (which is a Qt internal class).




回答4:


Does remote host require ssl connection? It may be problem if your Qt copy can't load libssl. I had same problem (UnkownSocketError) when Qt couldn't find libssl



来源:https://stackoverflow.com/questions/1885605/qabstractsocketunknownsocketerror

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!