PDA

View Full Version : Showing Hex Characters for Debug



nbkhwjm
13th July 2008, 01:31
Im receiving an ASCII string from a TCP Socket, I am getting some characters [LF,CR, FF, SP] that I need to identify in the stream. what I would like to do is to print the entire contents of the TCP REsponse to a qDebug output..

I have looked at QString, QTextStream, QByteArray Ref's but nothing is apparent.



void tcpparser::receiveData()
{
qDebug() << "DEBUG: Receiving Message";

QString responseLine;
QString response;

QTextStream in(&tcpSocket);

if( !QAbstractSocket::ConnectedState )
{
return;
}

while( tcpSocket.canReadLine() ){
responseLine = tcpSocket.readAll();
response.append(responseLine);

responseLine.toHex(); // Futile attempt to make it hex
qDebug() << "DEBUG: 0x" << debugResponseLine; // here is where im trying to get the debug
}
}

for example the tcp Socket will hear "THIS IS A MESSAGE" I want this as ASCII HEX so i can debug the parser...

thanks.

nbkhwjm
13th July 2008, 01:53
I did this to see whats up...



QString debugResponseLine;
debugResponseLine = responseLine;
debugResponseLine.toAscii();
debugResponseLine.replace(0x0a, "[LF]");
debugResponseLine.replace(0x0d, "[CR]");
debugResponseLine.replace(0x20, "[SP]");
debugResponseLine.replace(0x0c, "[FF]");
qDebug() << "DEBUG: 0x" << debugResponseLine;


im sure there is a better way with an array, but this is fine... comments are still welcome.

jpn
14th July 2008, 07:49
responseLine.toHex(); // Futile attempt to make it hex


Notice that this statement has no effect. QByteArray::toHex() returns a new hex encoded byte array.