Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Qt function body

Shulou Source: shulou.com Published: 2022-06-01 13:24:02 09月26日 Update

This article mainly explains "how to use the Qt function body". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the Qt function body".

Function name / / byte array to Ascii string static QString byteArrayToAsciiStr (const QByteArray & data); / / hexadecimal string to byte array static QByteArray hexStrToByteArray (const QString & str); static char convertHexChar (char ch); / / Ascii string to byte array static QByteArray asciiStrToByteArray (const QString & str); / / byte array to hexadecimal string static QString byteArrayToHexStr (const QByteArray & data) Function body QString QUIHelper::byteArrayToAsciiStr (const QByteArray & data) {QString temp; int len = data.size (); for (int I = 0; I

< len; i++) { //0x20为空格,空格以下都是不可见字符 char b = data.at(i); if (0x00 == b) { temp += QString("\\NUL"); } else if (0x01 == b) { temp += QString("\\SOH"); } else if (0x02 == b) { temp += QString("\\STX"); } else if (0x03 == b) { temp += QString("\\ETX"); } else if (0x04 == b) { temp += QString("\\EOT"); } else if (0x05 == b) { temp += QString("\\ENQ"); } else if (0x06 == b) { temp += QString("\\ACK"); } else if (0x07 == b) { temp += QString("\\BEL"); } else if (0x08 == b) { temp += QString("\\BS"); } else if (0x09 == b) { temp += QString("\\HT"); } else if (0x0A == b) { temp += QString("\\LF"); } else if (0x0B == b) { temp += QString("\\VT"); } else if (0x0C == b) { temp += QString("\\FF"); } else if (0x0D == b) { temp += QString("\\CR"); } else if (0x0E == b) { temp += QString("\\SO"); } else if (0x0F == b) { temp += QString("\\SI"); } else if (0x10 == b) { temp += QString("\\DLE"); } else if (0x11 == b) { temp += QString("\\DC1"); } else if (0x12 == b) { temp += QString("\\DC2"); } else if (0x13 == b) { temp += QString("\\DC3"); } else if (0x14 == b) { temp += QString("\\DC4"); } else if (0x15 == b) { temp += QString("\\NAK"); } else if (0x16 == b) { temp += QString("\\SYN"); } else if (0x17 == b) { temp += QString("\\ETB"); } else if (0x18 == b) { temp += QString("\\CAN"); } else if (0x19 == b) { temp += QString("\\EM"); } else if (0x1A == b) { temp += QString("\\SUB"); } else if (0x1B == b) { temp += QString("\\ESC"); } else if (0x1C == b) { temp += QString("\\FS"); } else if (0x1D == b) { temp += QString("\\GS"); } else if (0x1E == b) { temp += QString("\\RS"); } else if (0x1F == b) { temp += QString("\\US"); } else if (0x7F == b) { temp += QString("\\x7F"); } else if (0x5C == b) { temp += QString("\\x5C"); } else if (0x20 >

= b) {temp + = QString ("\\ x% 1") .arg (decimalToStrHex ((quint8) b));} else {temp + = QString ("% 1") .arg (b);}} return temp.trimmed ();} QByteArray QUIHelper::hexStrToByteArray (const QString & str) {QByteArray senddata; int hexdata, lowhexdata; int hexdatalen = 0; int len = str.length () Senddata.resize (len / 2); char lstr, hstr; for (int I = 0; I

< len;) { hstr = str.at(i).toLatin1(); if (hstr == ' ') { i++; continue; } i++; if (i >

= len) {break;} lstr = str.at (I). ToLatin1 (); hexdata = convertHexChar (hstr); lowhexdata = convertHexChar (lstr); if ((hexdata = = 16) | | (lowhexdata = = 16)) {break;} else {hexdata = hexdata * 16 + lowhexdata;} iTunes; senddata [hexdatalen] = (char) hexdata Hexdatalen++;} senddata.resize (hexdatalen); return senddata;} char QUIHelper::convertHexChar (char ch) {if ((ch > ='0') & & (ch ='A') & (ch ='a') & & (ch)

Tags: Functions characters strings bytes arrays binary learning content multiple that is ideas situations articles more knowledge knowledge points articles follow link questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology vpn Shulou Tech Info MariaDB