Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Как осуществить преобразование число (в частности типа int) в строку средствами QT?
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt Общие вопросы
Delphist
Как осуществить преобразование число (в частности типа int) в строку средствами QT?
Можно, конечно, вот так:
char sCode[25];
itoa(nCode, sCode, 10);

Но такое возможно только в компиляторе от Microsoft т.е. для Win32, а хотелось бы кроссплатформенно.
trdm
QString.setNum
AD
Цитата
QString.setNum
Можно и так!
А можно воспользоваться статической функцией QString::number

Цитата(Delphist @ 18.8.2008, 10:01) *
Можно, конечно, вот так:
char sCode[25];
itoa(nCode, sCode, 10);

Но такое возможно только в компиляторе от Microsoft т.е. для Win32, а хотелось бы кроссплатформенно.

Кстати, что-то я не в одной справке не видел, что itoa является внутренней функцией Microsoft (тем более для Win32)!
Цитата
Run-Time Library Reference
_itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow

Convert an integer to a string.

Parameters
value
Number to be converted.
string
String result.
radix
Base of value; must be in the range 2 – 36.
Return Value
Each of these functions returns a pointer to string. There is no error return.

Remarks
The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and stores the result (up to 33 characters for _itoa, 65 for _i64toa and _ui64toa) in string. If radix equals 10 and value is negative, the first character of the stored string is the minus sign ( – ). _itow, _i64tow, and _ui64tow are wide-character versions of _itoa, _i64toa, and _ui64toa respectively.

Security Note To prevent buffer overruns, ensure that the string buffer is large enough to hold the converted digits plus the trailing null-character and a sign character.

Так что впринципе и этой функцией тоже можешь пользоваться! Но Qt-шными просто немного удобнее.
ЙаМайскЫйПчОЛ
itoa, Помню в MSDN 2003 она был, с припиской POSIX))))
и в либах была. У нас из-за этого проект под линем не сразу собрался)

Вот еще вариант QString("%1").arg(int)...
Тож удобно.

забыл упомянуть sprintf().
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.