Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] Qt Example - QNetwork



  • Hello, I am playing around with "Qt example":http://qt-project.org/doc/qt-5.0/qtnetwork/torrent-peerwireclient-cpp.html 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 = socket.read(buffer, qMin<qint64>(sizeof(buffer), bytes - totalRead));
    if (bytesRead <= 0)
    break;
    qint64 oldSize = incomingBuffer.size();
    incomingBuffer.resize(oldSize + bytesRead);
    memcpy(incomingBuffer.data() + oldSize, buffer, bytesRead);

        totalRead += bytesRead;
    } while (totalRead < bytes);
    
    if (totalRead > 0) {
        downloadSpeedData[0] += totalRead;
        emit bytesReceived(totalRead);
        processIncomingData();
    }
    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":http://qt-project.org/doc/qt-5/qiodevice.html#readData is called by QIODevice



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


Log in to reply