A small summary of qbytearray usage

Source: Internet
Author: User
    Qbytearray Array;

    Array.resize (3);
    array[1]=0x7f;
    Qdebug ("I Array[1]=0x7f;array 1 is%d,%x", Qvariant (Array[1]). ToInt (), Qvariant (Array[1]). ToInt ());
    Qdebug ("I Array[1]=0x7f;__array 1 is%d,%x", array.at (1), array.at (1)); Qdebug ("I Array[1]=0x7f;___array 1 is%d,%x", Qvariant ((unsigned char) array[1]). ToInt (), Qvariant ((unsigned char) array [1]).

    ToInt ());
    Array[1]=0xff;
    Qdebug ("II Array[1]=0xff;array 1 is%d,%x", Qvariant (Array[1]). ToInt (), Qvariant (Array[1]). ToInt ());
    Qdebug ("II Array[1]=0xff;__array 1 is%d,%x", array.at (1), array.at (1)); Qdebug ("II Array[1]=0xff;___array 1 is%d,%x", Qvariant ((unsigned char) array[1]). ToInt (), Qvariant ((unsigned char)

    ARRAY[1]). ToInt ());
    ARRAY[1]=0X000000FF;
    Qdebug ("III Array[1]=0x000000ff;array 1 is%d,%x", Qvariant (Array[1]). ToInt (), Qvariant (Array[1]). ToInt ());
    Qdebug ("III Array[1]=0x000000ff;__array 1 is%d,%x", array.at (1), array.at (1)); Qdebug ("III Array[1]=0x000000ff;___array 1 is%d,%x", Qvariant ((UnsigneD char) array[1]. ToInt (), Qvariant ((unsigned char) array[1]). ToInt ());
    array[1]=-127;
    Qdebug ("IV Array[1]=-127;array 1 is%d,%x", Qvariant (Array[1]). ToInt (), Qvariant (Array[1]). ToInt ());
    Qdebug ("IV Array[1]=-127;__array 1 is%d,%x", array.at (1), array.at (1)); Qdebug ("IV Array[1]=-127;___array 1 is%d,%x", Qvariant ((unsigned char) array[1]). ToInt (), Qvariant ((unsigned char)

    ARRAY[1]). ToInt ());
    array[1]=0x7f01;
    Qdebug ("V Array[1]=0x7f01;array 1 is%d,%x", Qvariant (Array[1]). ToInt (), Qvariant (Array[1]). ToInt ());
    Qdebug ("V Array[1]=0x7f01;__array 1 is%d,%x", array.at (1), array.at (1)); Qdebug ("V Array[1]=0x7f01;___array 1 is%d,%x", Qvariant ((unsigned char) array[1]). ToInt (), Qvariant ((unsigned char)
     ARRAY[1]). ToInt ());



The output is:

I Array[1]=0x7f;array 1 is 127,7f
I Array[1]=0x7f;__array 1 is 127,7f
I Array[1]=0x7f;___array 1 is 127,7f
II Array[1]=0xff;array 1 is-1,ffffffff
II Array[1]=0xff;__array 1 is-1,ffffffff
II Array[1]=0xff;___array 1 is 255,ff
III Array[1]=0x000000ff;array 1 is-1,ffffffff
III Array[1]=0x000000ff;__array 1 is-1,ffffffff
III Array[1]=0x000000ff;___array 1 is 255,ff
IV Array[1]=-127;array 1 is-127,ffffff81
IV Array[1]=-127;__array 1 is-127,ffffff81
IV Array[1]=-127;___array 1 is 129,81
V Array[1]=0x7f01;array 1 is
V Array[1]=0x7f01;__array 1 is
V Array[1]=0x7f01;___array 1 is

As seen in the code and the results,

The elements in 1.QByteArray have 32 bits, but at the time of assignment array[] only the low 8 bits of the assigned value are stored, and the remaining high 24 bits in array[] are consolidated by 0 or 1 with the highest bit of the lower eight bits.

Elements in 2.QByteArray are signed

3.QByteArray can only use array[i]=value when assigning values, this form, array.at (i) is read-only, and forcing type conversions to array.at (i) does not work.

4. To read using its element value, if you want to get a signed number form, Qvariant (Array[i]). ToInt () is equivalent to array.at (i). If you get the unsigned number form of its element value, you need Qvariant ((unsigned char) array[i]). ToInt ()

5.array.data () points to its stored char*

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.