Conversion between qstring, Int, Char, and qbytearray in QT

Source: Internet
Author: User

 

Http://blog.csdn.net/ymc0329/article/details/7284514

 

 

Convert int to qstring
Int M = 1;
Qstring B;
B = qstring: Number (m)

Convert qstring to int
Qstring A = "1111"
Int B;
B = A. toint ()

Char to qstring
Char A = 'B ';
Qstring STR;
STR = qstring ();

Convert qstring to Char
Qstring STR = "QQ ";
Char * Ch;
Ch = Str. tolatin1.data ();

Conversion between char * and const char *
Char * character = "TT ";
Const char * CH2 = "QQ ";
CH2 = warning; // No error is reported, but a warning is reported.
Substring = (char *) CH2;

Convert qbytearray to char *
Char * Ch; // do not define it as CH [N];
Qbytearray byte;
Ch = byte. Data ();

Char * To qbytearray
Char * Ch;
Qbytearray byte;
Byte = qbytearray (CH );

Convert qstring to qbytearray
Qbytearray byte;
Qstring string;
Byte = string. toascii ();

Convert qbytearray to qstring
Qbytearray byte;
Qstring string;
String = qstring (byte );
Example:
Qdebug () <"QQ ";
Qdebug () <tr ("TT ");
Qdebug () <ch; (CH is char type)
Qdebug () <tr (CH );
Qdebug () <bytearray; (bytearray is of the qbytearray type)
Qdebug () <tr (bytearray );
Qdebug () <STR; (STR is of the qstring type)
However, qdebug () <tr (STR); is not acceptable. To use the tr () function to output qstring-type characters, you must:
Qdebug () <tr (Str. tolatin1 );

Qstring string

Qstring s2q (const string & S)

{
Return qstring (qstring: fromlocal8bit (S. c_str ()));
}


String q2s (const qstring & S)
{
Return string (const char *) S. tolocal8bit ());
}

Conversion between qstring, Int, Char, and qbytearray in QT

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.