Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractSocket::UnknownSocketError provides errorString of "UnknownError"

QAbstractSocket::UnknownSocketError provides errorString of "UnknownError"

Scheduled Pinned Locked Moved Unsolved General and Desktop
qabstractsocketsocketsocketerrornetwork socketnetwork
4 Posts 4 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CybeX
    wrote on 4 Feb 2017, 16:04 last edited by CybeX 2 Apr 2017, 16:16
    #1

    Problem

    I am unable to get any further information regarding this error:

    QAbstractSocket::UnknownSocketError
    

    The QT QAbstractSocket::SocketError provides only a basic explanation that some error has occurred

    An unidentified error occurred.

    enum value = -1

    Calling QTcpSocket::errorString() provides this:

    "Unknown error"
    

    There is one question regarding this here on SO but provides no real solution to solving the issue (and what was suggested I have done)

    I have absoltely no idea how to further progress with this error, since each time my client attempts to connect (after calling connectToHost()) I get this error.

    Code:

    //Server

    //...
    if (tcpServer.listen(QHostAddress().AnyIPv4, 5000)) {
        qDebug() << "tcpserver started on port : 5000";
    }
    else{
        qDebug() << "tcpserver failed to start";
    }
    //...
    

    I also went on to explicitly set the server ip to localhost and port 5000, but without success.

    //Client

    //...
    tcp_con = new QTcpSocket(new QObject());
    tcp_con->connectToHost("127.0.0.1", 5000);
    
    switch (tcp_con->error()) {
        //...
        case QAbstractSocket::UnknownSocketError:
        qDebug() << "tcp error UnknownSocketError closed : " << tcp_con->errorString();
        return;
        //...
    }
    

    Client debug output:

    tcp error UnknownSocketError closed :  "Unknown error"
    

    Any advice?

    p.s. I looked for some stacktrace/backtrace option, didn't find anything - if there is, please leave a comment

    K K 2 Replies Last reply 4 Feb 2017, 17:35
    0
    • C CybeX
      4 Feb 2017, 16:04

      Problem

      I am unable to get any further information regarding this error:

      QAbstractSocket::UnknownSocketError
      

      The QT QAbstractSocket::SocketError provides only a basic explanation that some error has occurred

      An unidentified error occurred.

      enum value = -1

      Calling QTcpSocket::errorString() provides this:

      "Unknown error"
      

      There is one question regarding this here on SO but provides no real solution to solving the issue (and what was suggested I have done)

      I have absoltely no idea how to further progress with this error, since each time my client attempts to connect (after calling connectToHost()) I get this error.

      Code:

      //Server

      //...
      if (tcpServer.listen(QHostAddress().AnyIPv4, 5000)) {
          qDebug() << "tcpserver started on port : 5000";
      }
      else{
          qDebug() << "tcpserver failed to start";
      }
      //...
      

      I also went on to explicitly set the server ip to localhost and port 5000, but without success.

      //Client

      //...
      tcp_con = new QTcpSocket(new QObject());
      tcp_con->connectToHost("127.0.0.1", 5000);
      
      switch (tcp_con->error()) {
          //...
          case QAbstractSocket::UnknownSocketError:
          qDebug() << "tcp error UnknownSocketError closed : " << tcp_con->errorString();
          return;
          //...
      }
      

      Client debug output:

      tcp error UnknownSocketError closed :  "Unknown error"
      

      Any advice?

      p.s. I looked for some stacktrace/backtrace option, didn't find anything - if there is, please leave a comment

      K Offline
      K Offline
      koahnig
      wrote on 4 Feb 2017, 17:35 last edited by
      #2

      @CybeX

      tcp_con = new QTcpSocket(new QObject());
      

      I do not understand what and why you are using a pointer to QObject there?

      I suggest to start with the use of default values. Therefore, change to:

      tcp_con = new QTcpSocket;
      

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      2
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 4 Feb 2017, 19:09 last edited by
        #3

        Hi,

        Your TCP server variable seems stack based. Does it get out of scope at some point ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • C CybeX
          4 Feb 2017, 16:04

          Problem

          I am unable to get any further information regarding this error:

          QAbstractSocket::UnknownSocketError
          

          The QT QAbstractSocket::SocketError provides only a basic explanation that some error has occurred

          An unidentified error occurred.

          enum value = -1

          Calling QTcpSocket::errorString() provides this:

          "Unknown error"
          

          There is one question regarding this here on SO but provides no real solution to solving the issue (and what was suggested I have done)

          I have absoltely no idea how to further progress with this error, since each time my client attempts to connect (after calling connectToHost()) I get this error.

          Code:

          //Server

          //...
          if (tcpServer.listen(QHostAddress().AnyIPv4, 5000)) {
              qDebug() << "tcpserver started on port : 5000";
          }
          else{
              qDebug() << "tcpserver failed to start";
          }
          //...
          

          I also went on to explicitly set the server ip to localhost and port 5000, but without success.

          //Client

          //...
          tcp_con = new QTcpSocket(new QObject());
          tcp_con->connectToHost("127.0.0.1", 5000);
          
          switch (tcp_con->error()) {
              //...
              case QAbstractSocket::UnknownSocketError:
              qDebug() << "tcp error UnknownSocketError closed : " << tcp_con->errorString();
              return;
              //...
          }
          

          Client debug output:

          tcp error UnknownSocketError closed :  "Unknown error"
          

          Any advice?

          p.s. I looked for some stacktrace/backtrace option, didn't find anything - if there is, please leave a comment

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 5 Feb 2017, 20:50 last edited by
          #4

          Don't get this the wrong way, but are you coming from Java? I'm asking because this:

          QHostAddress().AnyIPv4
          

          Doesn't make any sense in C++. What you probably want is to use the scope operator - :: to access one of the enum values. As for the error, please provide the full implementation of your TCP server and mention if you use threading, if so how. Also as mentioned by @koahnig

          new QTcpSocket(new QObject());
          

          This leaks 2 objects one socket and one generic QObject. You need to provide a valid pointer from the object tree to make use of the automatic deletion Qt supplies for child objects.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          3

          4/4

          5 Feb 2017, 20:50

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved