1. Convert to string format in the standard library
1. When programming Qt, since the cout function in the standard library cannot recognize the QString string, if you want to To use cout to output a QString string, you need to convert it to std::string.
2. To convert QString to std::string format, you only need to call the member function toStdString() of QString.
3. The following is the output of the above code. As you can see, the QString string is perfectly output using cout.
2. Convert to numeric format
1. Convert to int
If you want to convert QString to int, you can use the member function toInt of QString and pass Two parameters. Parameter one is a pointer of type bool, which returns the conversion result; parameter two is type int, which represents base. Note that since these two parameters have default values, if they are decimal numbers, they can be called directly without passing parameters.
For example, in the above example, the string "123" is converted into the decimal int value 123.
2. Convert to float
Similarly, QString can also be converted to the corresponding floating point number. For example, if you want to convert to float type, you can call the toFloat member function.
3. Convert to double
If you want to convert to double type, you can call the toDouble member function.