when i invoke toInt(), it return 0.
now i first use atoi(), and then QString::number();
but, it seems too much procedure???
how can i do that only using QString's method ?
thanks.
when i invoke toInt(), it return 0.
now i first use atoi(), and then QString::number();
but, it seems too much procedure???
how can i do that only using QString's method ?
thanks.
Try
and then take the integer part!
![]()
lanmanck (9th September 2009)
Alternatively, you can strip the decimals away from the string:
Works even if there isn't a decimal part, because str.left(-1) returns the whole string.Qt Code:
int number = str.left(str.indexOf('.')).toInt(); // == 100To copy to clipboard, switch view to plain text mode
Last edited by hkvm; 8th September 2009 at 16:34.
lanmanck (9th September 2009)
for me this should be enough:
Qt Code:
int x = str.toDouble();To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
lanmanck (9th September 2009)
i appreciate all the replyies![]()
Bookmarks