Important: Please read the Qt Code of Conduct -

[SOLVED] Qt Example - QNetwork

  • Hello, I am playing around with "Qt example": and there is one thing I don't really understand...

    How are readFromSocket and readData emited? I did not find it being called anywhere... I am trying to understand how to read incoming data from socket...

    @qint64 PeerWireClient::readFromSocket(qint64 bytes)
    char buffer[1024];
    qint64 totalRead = 0;
    do {
    qint64 bytesRead =, qMin<qint64>(sizeof(buffer), bytes - totalRead));
    if (bytesRead <= 0)
    qint64 oldSize = incomingBuffer.size();
    incomingBuffer.resize(oldSize + bytesRead);
    memcpy( + oldSize, buffer, bytesRead);

        totalRead += bytesRead;
    } while (totalRead < bytes);
    if (totalRead > 0) {
        downloadSpeedData[0] += totalRead;
        emit bytesReceived(totalRead);
    return totalRead;


    @qint64 PeerWireClient::readData(char *data, qint64 size)
    int n = qMin<int>(size, incomingBuffer.size());
    memcpy(data, incomingBuffer.constData(), n);
    incomingBuffer.remove(0, n);
    return n;

  • These are not signals and they are not emitted.
    readFromSocket is called by RateController::transfer() which is called by a timer
    readData, "according the the doc": is called by QIODevice

  • ohh... I did not see there are also other files... Thanks...

Log in to reply