Results 1 to 3 of 3

Thread: Showing Hex Characters for Debug

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Showing Hex Characters for Debug

    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.

    Qt Code:
    1. void tcpparser::receiveData()
    2. {
    3. qDebug() << "DEBUG: Receiving Message";
    4.  
    5. QString responseLine;
    6. QString response;
    7.  
    8. QTextStream in(&tcpSocket);
    9.  
    10. if( !QAbstractSocket::ConnectedState )
    11. {
    12. return;
    13. }
    14.  
    15. while( tcpSocket.canReadLine() ){
    16. responseLine = tcpSocket.readAll();
    17. response.append(responseLine);
    18.  
    19. responseLine.toHex(); // Futile attempt to make it hex
    20. qDebug() << "DEBUG: 0x" << debugResponseLine; // here is where im trying to get the debug
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    for example the tcp Socket will hear "THIS IS A MESSAGE" I want this as ASCII HEX so i can debug the parser...

    thanks.
    Last edited by nbkhwjm; 13th July 2008 at 01:37.

  2. #2
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: Showing Hex Characters for Debug

    I did this to see whats up...

    Qt Code:
    1. QString debugResponseLine;
    2. debugResponseLine = responseLine;
    3. debugResponseLine.toAscii();
    4. debugResponseLine.replace(0x0a, "[LF]");
    5. debugResponseLine.replace(0x0d, "[CR]");
    6. debugResponseLine.replace(0x20, "[SP]");
    7. debugResponseLine.replace(0x0c, "[FF]");
    8. qDebug() << "DEBUG: 0x" << debugResponseLine;
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Showing Hex Characters for Debug

    Quote Originally Posted by nbkhwjm View Post
    Qt Code:
    1. responseLine.toHex(); // Futile attempt to make it hex
    To copy to clipboard, switch view to plain text mode 
    Notice that this statement has no effect. QByteArray::toHex() returns a new hex encoded byte array.
    J-P Nurmi

Similar Threads

  1. about qt/embedded widgets showing in ARM platform
    By xianshuiren in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 3rd December 2007, 05:48
  2. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 14:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.