程序中需要将整型转换为字符串QString类型,看了看QString的构造函数,没有直接以int类型为参数的。
很奇怪,Qt一直给人感觉做什么都很方便,怎么会没有直接将整型转换为字符串的方法呢?难道还得自己写?
过一段时间后终于顿悟了,其实用QString的arg()函数可以完美解决其他类型转换为字符串的问题。
只需要:
int intValue;
QString strValue;
strValue = tr("%1").arg(intValue);
参考
程序中需要将整型转换为字符串QString类型,看了看QString的构造函数,没有直接以int类型为参数的。
很奇怪,Qt一直给人感觉做什么都很方便,怎么会没有直接将整型转换为字符串的方法呢?难道还得自己写?
过一段时间后终于顿悟了,其实用QString的arg()函数可以完美解决其他类型转换为字符串的问题。
只需要:
int intValue;
QString strValue;
strValue = tr("%1").arg(intValue);
参考