Character conversion in QT

Source: Internet
Author: User

Convert int and long to Char and string in QT

 

Convert Char to qstring

Qstring Buf = qstring (qlatin1string (char); // convert Char to qstring

Qstring value: Char

Str. tostdstring (). c_str ()

 

For example, char tockenid [60];

Qstring STR = UI-> lineedit_gettokenid-> text ();

 

Strcpy (tockenid, str. tostdstring (). c_str ());

 

Conversion between qstring string int double char * AND OTHER TYPES

The following summarizes several types of mutual transfer methods I know:

 

1 qstring --> string

 

Qstring. tostdstring ();

 

2 string --> qstring

 

Qstring: fromstdstring (string)

 

3 qstring ---> int, double, char *

 

Qstring: toint ()

 

Qstring: todouble ()

 

Qstring. tostdstring (). c_str ();

 

4 int double char * ---> string

 

You can use stringstream in <sstream>

 

Taking int as an example, int A = 3;

 

Stringstream SS;

 

String strint;

 

SS <;

 

SS> strint;

 

The other two are the same.

 

5 Int double char * qstring

 

You can convert string to qstring. Another method is to view functions of the qstring class.

 

Qstring: Number () static function. The parameter can be Int or double.

 

6 conversion of double int

 

Static_cast

 

 

 

Qstring: Number (long N, int base = 10) [Static]

 

A convenient function that converts a number n to a string. N is represented Based on base. The default value is 10 and must be between 2 and 36.

 

Long A = 63;

 

Qstring STR = qstring: Number (A, 16); // STR = "3f"

 

Qstring STR = qstring: Number (A, 16). Upper (); // STR = "3f"

 

You can also refer to setnum ().

 

Example: Action/application. cpp, application/application. cpp, chart/chartform. cpp,

 

Fonts/simple-qfont-demo/Viewer. cpp, MDI/application. cpp, and SQL/Overview/extract/Main. cpp.

 

Qstring: Number (ulong N, int base = 10) [Static]

 

This is an overloaded member function that provides convenience. Its behavior is basically the same as that of the above function.

 

You can also refer to setnum ().

 

Qstring: Number (int n, int base = 10) [Static]

 

This is an overloaded member function that provides convenience. Its behavior is basically the same as that of the above function.

 

You can also refer to setnum ().

 

Qstring: Number (uint N, int base = 10) [Static]

 

This is an overloaded member function that provides convenience. Its behavior is basically the same as that of the above function.

 

A convenient manufacturing function that converts the number n to a string. N is represented Based on base. The default value is 10 and must be between 2 and 36.

 

You can also refer to setnum ().

Convert int and long to Char and string in QT

 

Convert Char to qstring

Qstring Buf = qstring (qlatin1string (char); // convert Char to qstring

Qstring value: Char

Str. tostdstring (). c_str ()

 

For example, char tockenid [60];

Qstring STR = UI-> lineedit_gettokenid-> text ();

 

Strcpy (tockenid, str. tostdstring (). c_str ());

 

Conversion between qstring string int double char * AND OTHER TYPES

The following summarizes several types of mutual transfer methods I know:

 

1 qstring --> string

 

Qstring. tostdstring ();

 

2 string --> qstring

 

Qstring: fromstdstring (string)

 

3 qstring ---> int, double, char *

 

Qstring: toint ()

 

Qstring: todouble ()

 

Qstring. tostdstring (). c_str ();

 

4 int double char * ---> string

 

You can use stringstream in <sstream>

 

Taking int as an example, int A = 3;

 

Stringstream SS;

 

String strint;

 

SS <;

 

SS> strint;

 

The other two are the same.

 

5 Int double char * qstring

 

You can convert string to qstring. Another method is to view functions of the qstring class.

 

Qstring: Number () static function. The parameter can be Int or double.

 

6 conversion of double int

 

Static_cast

 

 

 

Qstring: Number (long N, int base = 10) [Static]

 

A convenient function that converts a number n to a string. N is represented Based on base. The default value is 10 and must be between 2 and 36.

 

Long A = 63;

 

Qstring STR = qstring: Number (A, 16); // STR = "3f"

 

Qstring STR = qstring: Number (A, 16). Upper (); // STR = "3f"

 

You can also refer to setnum ().

 

Example: Action/application. cpp, application/application. cpp, chart/chartform. cpp,

 

Fonts/simple-qfont-demo/Viewer. cpp, MDI/application. cpp, and SQL/Overview/extract/Main. cpp.

 

Qstring: Number (ulong N, int base = 10) [Static]

 

This is an overloaded member function that provides convenience. Its behavior is basically the same as that of the above function.

 

You can also refer to setnum ().

 

Qstring: Number (int n, int base = 10) [Static]

 

This is an overloaded member function that provides convenience. Its behavior is basically the same as that of the above function.

 

You can also refer to setnum ().

 

Qstring: Number (uint N, int base = 10) [Static]

 

This is an overloaded member function that provides convenience. Its behavior is basically the same as that of the above function.

 

A convenient manufacturing function that converts the number n to a string. N is represented Based on base. The default value is 10 and must be between 2 and 36.

 

You can also refer to setnum ().

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.