Is there a QString
function which takes an int and outputs it as a QString
?
You can use: QString qs; // do things std::cout << qs. toStdString() << std::endl; It internally uses QString::toUtf8() function to create std::string, so it's Unicode safe as well.
Conversion of an integer into a string by using to_string() method. The to_string() method accepts a single integer and converts the integer value or other data type value into a string.
The next method in this list to convert int to string in C++ is by using the to_string() function. This function is used to convert not only the integer but numerical values of any data type into a string. The to_string() method is included in the header file of the class string, i.e., <string> or <cstring>.
Use QString::number()
:
int i = 42; QString s = QString::number(i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With