Formatting Numbers
Hi guys,
I’m new on developing software on Qt. I would like to get some numbers formatted as string with 2 digits for every numbers. This to get the numbers with value < 9 formatted as “09”.
I’m using the lines of code below but they don’t give me back what I would like to obtain and I can’t understand where the mistake is. Please could you help me and check my code?
- uint hours=1, minutes=2, seconds=3;
- .arg(hours, 1, 10)
- .arg(minutes, 2, 10, '0')
- .arg(seconds, 2, 10, '0');
- ui->chronoDisplay->setText(str); //chronoDisplay is a QLabel
- //I'm expecting that str has got this format: "1:02:03"
Thank you in advance.
14 replies
I guess that this is getting in your way:
If fillChar is ‘0’ (the number 0, ASCII 48), the locale’s zero is used.
(from the QString documentation)
I am wondering, why you are not using QTime to format your time:
- ui->chronoDisplay->setText(t.toString("h:mm::ss"));
Edit: fixed second line of above code (replaced QTime:: with t. )
I guess that this is getting in your way:If fillChar is ‘0’ (the number 0, ASCII 48), the locale’s zero is used.(from the QString documentation) I am wondering, why you are not using QTime to format your time:
Just because I didn’t know this possibility… Now that I know it I’m going to try to use it!
Thank you for the advice!
Ok, this is the result I’m gettim from the simulator after the code is processed.

this is the URL of the image:
http://www.softwareprojects.it/images/blogimages/software/nokiaSimulator.png
Why this code worked just one time and now it doesn’t work again?
This is the error I’m receiving when I try to use the code above
C:\Documents and Settings\tlp31\Documenti\C++_Project\chrono-build-simulator\..\chrono\mainwindow.cpp:120: error: cannot call member function ‘QString QTime::toString(const QString&) const’ without object
and this is the code:
You must log in to post a reply. Not a member yet? Register here!


