问题
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.cppon line 2025) - An SSL error occurred (
src/network/ssl/qsslsocket_openssl.cppin 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