Results 1 to 5 of 5

Thread: qDebug donsn't display 0x00

  1. #1
    Join Date
    Mar 2013
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qDebug donsn't display 0x00

    hi every body
    my problem in displaying array of hex, the qDebug displays only first 5 characters and treated the sixth charterer as null and it doesn't display the rest.how can i display full array ???
    quint64 index =0;
    char CMD[100];
    CMD[index++]=0x57;
    CMD[index++]=0x58;
    CMD[index++]=0x10;
    CMD[index++]=0x11;
    CMD[index++]=0x21;
    CMD[index++]=0x00;
    CMD[index++]=0x00;
    CMD[index++]=0x00;
    CMD[index++]=0x00;
    CMD[index++]=0x00;
    CMD[index++]=0x00;
    CMD[index++]=0x00;
    CMD[index++]=0x00;
    qDebug()<<"CMD"<<(QString::fromStdString(CMD).toAs cii().toHex());

    output is only:
    "5758101121"

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: qDebug donsn't display 0x00

    Do not convert to QString, instead directly convert to QByteArray.
    Qt Code:
    1. qDebug() << "CMD" << QByteArray(CMD, index).toHex();
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2013
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qDebug donsn't display 0x00

    thanks very much

    what about displaying CMD hex values in LineEdit ,which accept string valuses

    for example
    ui->Label->setText(QString::fromStdString(CMD).toAscii().toH ex);

    i don't want to convert hex valuse of CMD toHex();

    sorry i want convert the hex values to Ascii

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qDebug donsn't display 0x00

    CMD does not contain anything in hex, it's a bucket of bytes stored in an array. If you have a bucket-o-bytes and you want to display that as a string of human-readable numbers in hex then you must, by definition, convert the bytes in some way. If you try to treat the bucket-o-bytes as a standard C-string, i.e. toAscii(), then it will be terminated by the first NUL byte: so don't do that. Santosh Reddy has already told you how to achieve this conversion using QByteArray, and all you have to do is look at the constructors of QString to finish the job.

  5. #5
    Join Date
    Mar 2013
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qDebug donsn't display 0x00

    yes i got it in qdebug
    but my problem is display the CMD in setText()

    say in case conversion CMD to QbyteArray .how can display the QbyteArray as hex display in setText();??ui->Label->setText(Qstring:: ????(Command));


    Added after 30 minutes:


    i solved it

    QByteArray Command(CMD,index);
    QString Result=Command.toHex();
    ui->Label->setText(Result);

    it works fine...
    Many thanks Santosh Reddy & ChrisW67
    Last edited by SwanseaLover; 22nd April 2013 at 05:32.

Similar Threads

  1. Replies: 2
    Last Post: 3rd July 2012, 16:42
  2. qDebug string display
    By zgulser in forum Newbie
    Replies: 9
    Last Post: 2nd July 2012, 13:59
  3. (char) 0x00
    By saman_artorious in forum Qt Programming
    Replies: 8
    Last Post: 25th June 2012, 11:25
  4. qDebug() on OSX
    By December in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2008, 17:14
  5. qdebug
    By drkbkr in forum Qt Programming
    Replies: 12
    Last Post: 29th September 2006, 15:26

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.