组合字符串的另一个函数是QString::sprintf(),此函数支持的格式定义和C++库中的函数sprintf()定义一样,例如:
QString str;
str.sprintf("%s","Welcome "); //str = "Welcome "
str.sprintf("%s"," to you! "); //str = " to you! "
str.sprintf("%s %s","Welcome "," to you! "); //str = "Welcome to you! ";
section()函数用于拆分字符串
QString QString::section ( QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault ) const
QString str;
QString csv = "forename,middlename,surname,phone";
QString path = "/usr/local/bin/myapp"; // First field is empty
QString::SectionFlag flag = QString::SectionSkipEmpty;
str = csv.section(',', 2, 2); // str == "surname"
qDebug()<<str;
str = path.