1 开发环境
在介绍内容之前,先说明一下开发环境,如下图:
Qt版本:Qt5.3.2;
Qt开发工具:Qt Creater 3.2.1;
Qt构建工具:Desktop Qt 5.3 MinGW 32bit;
Qt开发平台:Windows 7 64bit。
2 QString
今天介绍QString的转换部分的功能,之前的内容可以参考以下链接。
0022:Qt常用类 - QString(01,QString的编码方式和初始化)
0023:Qt常用类 - QString(02,增加)
0024:Qt常用类 - QString(03,删除)
0025:Qt常用类 - QString(04,修改)
0026:Qt常用类 - QString(05,查询)
0027:Qt常用类 - QString(06,遍历)
0028:Qt常用类 - QString(07,子字符串)
0029:Qt常用类 - QString(08,格式化)
0030:Qt常用类 - QString(09,比较)
下面是转换部分的示例代码。
/*
* --- 数字转换 ---
* QString & setNum(int n, int base = 10)
* QString & setNum(uint n, int base = 10)
* QString & setNum(long n, int base = 10)
* QString & setNum(ulong n, int base = 10)
* QString & setNum(qlonglong n, int base = 10)
* QString & setNum(qulonglong n, int base = 10)
* QString & setNum(short n, int base = 10)
* QString & setNum(ushort n, int base = 10)
* QString & setNum(double n, char format = 'g', int precision = 6)
* QString & setNum(float n, char format = 'g', int precision = 6)
* short toShort(bool * ok = 0, int base = 10) const
* int toInt(bool * ok = 0, int base = 10) const
* long toLong(bool * ok = 0, int base = 10) const
* qlonglong toLongLong(bool * ok = 0, int base = 10) const
* ushort toUShort(bool * ok = 0, int base = 10) const
* uint toUInt(bool * ok = 0, int base = 10) const
* ulong toULong(bool * ok = 0, int base = 10) const
* qulonglong toULongLong(bool * ok = 0, int base = 10) const
* float toFloat(bool * ok = 0) const
* double toDouble(bool * ok = 0) const
* QString QString::::number(long n, int base = 10)
* QString QString::::number(double n, char format = 'g', int precision = 6)
* QString QString::::number(ulong n, int base = 10)
* QString QString::::number(int n, int base = 10)
* QString QString::::number(uint n, int base = 10)
* QString QString::::number(qlonglong n, int base = 10)
* QString QString::number(qulonglong n, int base = 10)
*
* --- 编码转换 ---
* QString & setRawData(const QChar * unicode, int size)
* QString & setUnicode(const QChar * unicode, int size)
* QString & setUtf16(const ushort * unicode, int size)
* QByteArray toUtf8() const
* QVector<uint> toUcs4() const
* std::string toStdString() const
* std::wstring toStdWString() const
* int toWCharArray(wchar_t * array) const
* const QChar * unicode() const
* const ushort * utf16() const
* QString QString::fromRawData(const QChar * unicode, int size)
* QString QString::fromStdString(const std::string & str)
* QString QString::fromStdWString(const std::wstring & str)
* QString QString::fromUcs4(const uint * unicode, int size = -1)
* QString QString::fromUtf8(const char * str, int size = -1)
* QString QString::fromUtf8(const QByteArray & str)
* QString QString::fromUtf16(const ushort * unicode, int size = -1)
* QString QString::fromWCharArray(const wchar_t * string, int size = -1)
*
* --- 大小写转换 ---
* QString toLower() const
* QString toUpper() const
*/
//由于看函数名称,基本就知道怎么用了,所以不写实例代码了...