Keyword in



  • I can't understund how keyword work "in" can you explain it me?

    void ServerStuff::readClient()
    {
       // QTcpSocket *clientSocket = (QTcpSocket*)sender();
        QTcpSocket *clientSocket = static_cast<QTcpSocket*>(sender());
    
    **//do you need to pass the contents in clientSocket  to QdataStream?**
    
        QDataStream in(clientSocket);
        //in.setVersion(QDataStream::Qt_5_10);
        for (;;)
        {
            if (!m_nNextBlockSize)
            {
                if (clientSocket->bytesAvailable() < sizeof(quint16)) { break; }
                in >> m_nNextBlockSize;
            }
    
            if (clientSocket->bytesAvailable() < m_nNextBlockSize) { break; }
            QString str;
            in >> str;
    
            emit gotNewMesssage(str);
    
            m_nNextBlockSize = 0;
    
            if (sendToClient(clientSocket, QString("Reply: received [%1]").arg(str)) == -1)
            {
                qDebug() << "Some error occured";
            }
        }
    }
    
    
    


  • in isn't a keyword. it is an object of type QDataStream. In the context you are using it it is a stream object to read from a socket using the streams operators.



  • @Kent-Dorfman said in Keyword in:

    in isn't a keyword. it is an object of type QDataStream. In the context you are using it it is a stream object to read from a socket using the streams operators.

    thanks, in this way is passed to the object "in" as an argument (clientSocket)?


  • Qt Champions 2018

    @Nio74 clientSocket is passed as parameter/argument to "in", so "in" will read from clientSocket



  • tanks everyone,I think that I have understund


Log in to reply