Mutual transformation and network data transmission between int, Byte, Qbytearray and Qstring in QT

Source: Internet
Author: User

Qhostaddress ServerIP;
Serverip.setaddress (QString ("192.168.0.7"))//This is a method of assigning IP addresses artificially

Qbytearray Array;
Array.resize (2);
array[0]=0x00;
array[1]=0x04;
BOOL OK;
Char byte1=qstring ("a"). ToInt (&ok,16);
Char byte2=qstring ("a"). ToInt (&ok,16);
array[0]=byte1;
Array[1]=byte2;
Clientudp->writedatagram (array,serverip,1111);//write data to port 1111

Above is a section of code that sends a byte array to Udpsocket, and the annotated part is also available. Char byte2=qstring ("a"). ToInt (&ok,16), which means that "04" is interpreted as an integer according to the 16 number (integer is a data type, there is no distinction of the so-called binary, the integer returned here is by default in decimal notation), Then chop off the first 24 bits to assign to a char type.

In addition to the transmission of data in the network (cable) is a unified big-end storage, but the data before and after receiving the affirmative byte sequence is consistent, will not be reversed, so you can think that the network transmission size of the way is the program ape transparent. (But sometimes if the local machine does not match this, it needs to be corrected). I tested it on my PC and arm and found that both sides were small, no need to fix

int Hex=str.toint (&ok,16);//The qstring is interpreted as a 16-digit number and returns the decimal integer

QString (ByteArray);//byte array conversion to QString

Qbytearray::tohex (), fromhex;//don't know exactly what to do.

Qbytearraybyte a=string.toascii;//don't know exactly what to do with the Welcome master correct

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.