1. Convert qstring to Char
*
First convert qstring to qbytearray, then convert qbytearray to Char
*.
Note: The following conversion form cannot be char * Mm = Str. tolatin1 (). Data ();. In this case, the qbytearray result obtained by Str. tolatin1 () cannot be saved, and the value of MM is null after the final conversion.
2. char *
Convert qstring
You can use the constructor of qstring to convert: qstring (const
Qlatin1string & Str );
Constructor of qlatin1string: qlatin1string (const
Char * Str );
The following statement converts char * mm to qstring.
STR:
STR = qstring (qlatin1string (MM ));
Example:
// # Include "myclass. H "<br/> # include <qtgui/qapplication> <br/> # include <qtdebug> <br/> # include <qstring> </P> <p> int main (INT argc, char * argv []) <br/>{< br/> qapplication A (argc, argv); </P> <p> qstring STR = "hello "; // convert qstring to char * <br/> qbytearray BA = Str. tolatin1 (); <br/> char * Mm = BA. data (); <br/> qdebug () <mm <Endl; // when debugging, output in the console </P> <p> qstring nn = qstring (qlatin1string (MM); // char * To qstring <br/> qdebug () <NN <Endl; // output in the console during debugging </P> <p> // myclass W; <br/> // W. show (); <br/> return a.exe C (); <br/>}</P> <p>
Debug and output the following content on the console:
Hello
Hello