Hi,
I am using Qt4 to develop a simple chat client for school. I have already asked this question on qtforums.org but never got a response, I am hoping that someone here has some knowledge of Qt and can shed some light on this problem for me. I have basically taught myself OO programming for this project, so I realise that my design is probably not the best, but this bug is baffling me. Here is the relevant code
This slot/function is executed everytime the readyRead() signal is emitted which means that data is available to read from the network socket. The function is called, but receivedMessage is always blank so it isn't reading from the socket. But there is no reason it shouldn't, it's definetely connected and will send data to netcat and this function is called to read the data and display except it only reads a blank string. I would appreciate any replies or suggestions, I will post all code on request, it's just that's it's a few hundred lines so I am a little hesitant.Code:void Kether::readData() { //qDebug("In readData start"); QDataStream in(tcpSocket); in.setVersion(QDataStream::Qt_4_2); /* if (blocksize == 0) { if (tcpSocket->bytesAvailable() < (int)sizeof(quint16)) { qDebug("in first return"); return; } in >> blocksize; } if (tcpSocket->bytesAvailable() < blocksize) { qDebug("in second return"); return; } */ QString receivedMessage; in >> receivedMessage; qDebug() << "receivedMessage:" << receivedMessage; ui.chatWindow->append(receivedMessage); qDebug("In readData end"); }
Thanks in advance,
Calef13