tags:

views:

100

answers:

4

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.

A: 

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

Intransigent Parsnip
I've just checked your idea against my code. No, this error code is emitted with the QAbstractSocket::error signal. I've edited the question to reflect this fact.
Anton
A: 

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).

guruz
Unfortunately, I have no opportunity to debug the code since it is a windows service being run on a remote server, and described behavior doesn't reproduce all the time.
Anton
A: 

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

Kamil Klimek
No, the connection is pure TCP. Thanks for answer anyway.
Anton
+1  A: 

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.

andref
Thanks for the tip, I'll try logging errorString().
Anton