Qt between Qstring,char,int,qbytearray to conversion

Source: Internet
Author: User
11, various data types of mutual conversion
Conversion of char * to const char *
Char *ch1= "hello11";
const char *ch2= "HELLO22";
CH2 = ch1;//No error, but warning
CH1 = (char *) CH2;

Convert Char to QString
In fact, there are a lot of methods, I use:
Char a= ' B ';
QString str;
Str=qstring (a);

QString conversion to Char
Methods are also used in many
QString str= "ABC";
Char *ch;
ch = str.toLatin1.data ();

Qbytearray conversion to char *
Char *ch;//not defined as ch[n];
Qbytearray byte;
ch = byte.data ();

char * converted to Qbytearray
Char *ch;
Qbytearray byte;
byte = Qbytearray (CH);

QString conversion to Qbytearray
Qbytearray byte;
QString string;
byte = String.toascii ();


Qbytearray conversion to QString
Qbytearray byte;
QString string;
string = QString (byte);
Here we summarize the output of the two types:
Qdebug () << "print";
Qdebug () <<tr ("print");
Qdebug () <<ch; (ch is char type)
Qdebug () <<tr (CH);
Qdebug () <<byteArray; (ByteArray is Qbytearray type)
Qdebug () <<tr (ByteArray);
Qdebug () <<str; (str to qstring type)
But Qdebug () <<tr (str), it is not possible to use the TR () function to output the characters of the qstring type as follows:
Qdebug () <<tr (str.tolatin1);

int turn QString
int a=10;
QString b;
B=qstring::number (a)

QString ext. int
QString a= "120"
int b;
B=a.toint ()

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.