Uncommon usage of qstring

Source: Internet
Author: User

QString Str ("Hello");

QString str = "Hello";

static const Qchar Data[4] = {0x0055, 0x006e, 0x10e3, 0x03a3};
QString Str (data, 4);

QString str;
Str.resize (4);

Str[0] = Qchar (' U ');
STR[1] = Qchar (' n ');
STR[2] = Qchar (0X10E3);
STR[3] = Qchar (0X03A3);

QString str;
str.sprintf ("%s%.3f", "float", 3.1415926);
Str result is "float 3.14"

QString str;
Str.setnum (10); str = "10"
Str.setnum (10, 16); str = "a"
Str.setnum (10.12345); str = "10.12345"

QString i; Current file ' s number
QString Total; Number of files to process
QString FileName; Current file ' s name

QString status = QString ("Processing file%1 of% 2:%3")
. Arg (i). Arg (total). Arg (fileName);

Reference: http://blog.csdn.net/xgbing/article/details/7770854

------------------------------------------------------------------

1) Char * initialization

QString str = "Hello";

QString converts the const char * data into Unicode using the Fromascii () function.

2) qchar[] array initialization

CPP Code
    1. Static const Qchar Data[4] = {0x0055, 0x006e, 0x10e3, 0x03a3};
    2. QString Str (data, 4);

You can do that.

CPP Code
    1. Qregexp pattern;
    2. Static const Qchar unicode[] = {0x005a, 0x007F, 0X00A4, 0x0060,
    3. 0x1009, 0x0020, 0x0020};
    4. int size = sizeof (Unicode)/ sizeof (QCHAR);
    5. QString str = qstring::fromrawdata (Unicode, size);

3) can also be initialized with the risize () function and each Qchar character

CPP Code
    1. QString str;
    2. Str.resize (4);
    3. Str[0] = Qchar (' U ');
    4. STR[1] = Qchar (' n ');
    5. STR[2] = Qchar (0X10E3);
    6. STR[3] = Qchar (0X03A3);

Each character read through the at () function

CPP Code
    1. QString str;
    2. For (int i = 0; i < str.size (); ++i) {
    3. if (str.at (i) >= Qchar (' a ') && str.at (i) <= Qchar (' F '))
    4. Qdebug () << "Found character in range [a-f]";
    5. }

Reference: http://qimo601.iteye.com/blog/1432867

Uncommon usage of qstring

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.