Displaying integer and float numbers in a QPlainTextEdit object
-
22-03-2021 - |
Question
I want to display a numerical value in a QPlainTextEdit object. I use below code for this purpose.
QString s;
s.sprintf("%d", deneme); //deneme is an integer value.
ui->results->setPlainText(s);
Is there any other method for displaying integer and float numbers in a QPlainTextEdit without defining a new QString object.
Thanks.
Solution
QString::number()
You still have to create a QString
instance (that is what QPlainTextEdit
requires), but this may be at least a little more convenient.
There are a bunch of overloads of that method to accommodate various input and output formats.
OTHER TIPS
How about:
ui->results->setPlainText(QString("%1").arg(deneme));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow