Skip to content
  • 0 Votes
    4 Posts
    5k Views
    kshegunovK

    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.

  • 0 Votes
    16 Posts
    10k Views
    B

    @Mark81 Sorry I have misled you, I was confusing the timeout on the wait...() functions with the asynchronous signals. You do not want the wait...() functions in the GUI thread as they block.

    The first thing to note is that normal TCP/IP will retry 12 times to send a data segment taking up to 9 minutes before it causes an error.

    I think you have two choices in the normal TCP/IP framework.

    If you are sending data and expecting a reply, you can start a single shot timer that is cancelled if the reply is received but causes your communications failed code to run when it times out.

    If you are just waiting for data then you will get no notification of errors as TCP/IP will wait forever on a disconnected circuit. So in this case you must have your server send you periodic "heartbeat" data to confirm its reachability.

  • 0 Votes
    2 Posts
    3k Views
    UndeadBlowU

    Ok, i got it:

    // Disambiguate overloaded member function below with static cast connect(socket, static_cast<void (QTcpSocket::*) (QAbstractSocket::SocketError)>(&QTcpSocket::error), this, &Network::socketErrorSlot);

    I think that deserves to be in bugtracker, isn't it? Not good idea to implement new notation and use the same names for method and signal.