索引at;返回在索引i处的字符,或者如果i超过字符串的长度返回0
const QString string( "abcdefgh" );
QChar ch = string.at( 4 );
QString toLower() //转换为小写
QString toUpper() //转换成大写
QString c("cle");
QString str=c.toUpper(); // str == "cle"
qDebug()<<str;
尾部插入append;push_back
头部插入prepend;push_front
QString cer = "data";
cer.append("list");
cer.push_back("yes");
cer.prepend("like");
cer.push_front("good");
qDebug()<<cer;
基本类型转换
s1.toUInt();
s1.toDouble();
s1.toFloat();
s1.toShort();
s1.toLong();
s1.toULongLong();
长度
s1.size()
s1.count();
s1.length();
如果字符串为零,返回真。零字符串总是空的。
QString a; // a.unicode() == 0,a.length() == 0
a.isNull(); // 真,因为a.unicode() == 0
a.isEmpty(); // 真
比较
int a = QString::compare( "def", "abc" ); // a > 0
int b = QString::compare( "abc", "def" ); // b < 0
int c = QString::compare(" abc", "abc" ); // c == 0
删除字符串中间某个字符
QString str = "Hello World!";
str.remove(5, 6); // str = "Hello!"
指定位置插入字符
QString str = "Hello!";
str.insert(5, QString(" World")); // str = "Hello World!"
QString::number 整数转换
int a = 20;
uint b =255;
QString::number(a);
QString::number(a,10);
QString::number(b);
QString::number(b,16);
以上为QString常用简单例子;更多例子等待着我们探索!