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. [SOLVED] Qt Example - QNetwork

[SOLVED] Qt Example - QNetwork

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 982 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 13 Mar 2014, 19:20 last edited by
    #1

    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;
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 13 Mar 2014, 20:26 last edited by
      #2

      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

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on 13 Mar 2014, 21:39 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        13 Mar 2014, 19:20

        • Login

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