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 ().