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. QTcpSocket status is incorrect

QTcpSocket status is incorrect

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 865 Views 1 Watching
  • 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.
  • L Offline
    L Offline
    Larryad
    wrote on last edited by
    #1

    I am using Qt 4.8.2 (64 bit) on Linux Debian.

    I am having problem with socket status. I am client connecting to server, my relevant code snippet is:

    QTcpSocket *socket = new QTcpSocket(this);
    socket->connectToHost(interface[cameras[listnum].interface].ip,interface[cameras[listnum].interface].port);
    qDebug() << socket->waitForConnected(10000);
    qDebug() << socket->isValid();
    qDebug() << socket->state();

    I am connecting to server that is local to me and I can disconnect Ethernet cable to it to test both connected and non-connected states. I can tell if I connect by the wait time, if cable is connected to server then waitForConnected takes less than 0.5 seconds and if cable is not connected then waitForConnected times out at 10 seconds.

    My problem is I get the same status connected or not. The output of the qDebug is:

    false
    true
    QAbstractSocket::UnconnectedState

    And it stays this way if I am really connected or not. When connected I can send data. I also put the last two statements in command button and verified the return status does not change even after several seconds or minutes.

    Any help pointing me in the right direction would be most appreciated.

    1 Reply Last reply
    0

    • Login

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