Qbytearray assignment and display in Qt5.9 and storage form (Tohex () function)

Source: Internet
Author: User

This article mainly summarizes the usage of the Qbytearray class, mainly summarizes how to assign a value of 16 to the Qbytearray object and display the hexadecimal number and hexadecimal number in the Qbytearray storage form, the specific example is as follows: (the hexadecimal number of characters: ' \ XFF ')

(QT Qbytearray Storage hexadecimal number is 0xFF, is actually stored in the ASCLL code, the storage form of ' \xff ', so if need to compare, need to use array.at (0) = = ' \xff ' expression, instead of array.at (0) = = 0xFF)

(to know whether the Qbytearray contains an int integer, or the character ' F ', if it is an int integer, it is judged by int or hex, and if the character ' F ' is the character ' F ', then it is judged by the characters:

For example, Qbytearray content is: FF, that is, qbytearray[0]=f,qbytearray[1]=f, then Qbytearray is stored two characters ' F ' instead of an integer 255.

For example Qbytearray content is: FF, that is, QBYTEARRAY[0]=FF, then Qbytearray is stored in an integer 255, instead of two characters ' FF '.


1.1 Create a new widget project, the base class is selected as Qwidget. Drag a pushbutton button into the UI interface.

1.2 Add the Slot function of the button and add the following code to the button slot function:


1.3 After the program is built, the results are as follows:



The above results indicate that the array array is 1 bytes long and can be assigned to the NO. 0 byte of array by hexadecimal number, i.e. code array[0] = 0xfE; When the hexadecimal number is assigned, the hexadecimal number takes up one byte of the array, and when you view the contents of the byte, you can use the function Tohex () to display the hexadecimal number (a byte of space).  With the Qdebug class can be done, that is, Code Qdebug () <<array.tohex (); This functionality can be implemented. Of course, the assignment of 16 can also use characters to denote ' \x0fe ' = = 0xfE, that is, ' \x0fe ' is equivalent to 0xfE.



Reference content:

http://blog.csdn.net/u012627502/article/details/27060477 (explains how to modify the contents of an Qbytearray array, such as add, decrease, replace, middle Insert, start with n characters from the middle)

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.