Why using quint16 or quint32 in QDataStream ?



  • This is very simple program that act as client of QDataStream which I found this online

    I am wondering can someone explain why they used blockSize which is quint16 ?

    @ void Client::request()
    {
    this->blockSize = 0;//unsigned short
    this->socket->abort();//clear buffer
    this->socket->connectToServer(this->hostLineEdit->text());
    }

    void Client::read()
    {
    QDataStream input(socket);

     if (blockSize == 0) {
         if (socket->bytesAvailable() < (int)sizeof(quint16))
             return;
         input >> blockSize;
     }
    

    ....
    }@


  • Lifetime Qt Champion

    Hi,

    Base on my experience: because the maximal size of data they will send can be stored in a quint16 and so the client will know how much data it will receive so it can wait to have it all before processing it.

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.