View Full Version : converiosn of hex data char array to Qstring

17th March 2010, 08:33
hi users
i am using for last one year.
but i am having one problem.
as per my new requirement i have to receive hex data from RS422 port and display the received hex data in any display widget.

so i started to code.
my code has one unsigned char array and few more widgets for other opeartions

my code looks like thsi

unsigned received_hexbuff[62];


QString display_textr(received_hexbuff);
QLabel display_lbl;
when i compile this code it is showing in compatible QString constructor call.

then i refer Qt docs. there i found QString constructor accpet only const char * argument type only.

so i badly requir to convert my char array to QString which is used to display the hex data as it is.

i request somebody to help me.
thanks in advance....

17th March 2010, 09:04
I'm sure this question has been asked before but it is difficult to search for "hex" although "hexadecimal" gets hits.

You will need to explain what you want more clearly. "Hex data char array" could mean a number of things.

Is the data stream coming from your serial interface:
A series of bytes of any value that you wish to convert to a hexadecimal string. That is the interface receives 8 bytes ( 0x51 0x74 0x43 0x65 0x6e 0x74 0x72 0x65 ) and you want to display the 16 character string "517443656e747265". Look at QByteArray::toHex () and QString::QString ( const QByteArray & ba ).
A series of text characters that are the hexadecimal representation that you wish to convert to a binary data array. That is, the serial port receives 16 bytes ("517443656e747265") and you wish to display the 8 character string "QtCentre". Look at QByteArray::fromHex() and QString::QString ( const QByteArray & ba )
Something else.