QT 常用到的QString字符串拼接用法:
方式1:
QString str1 = "Welcome";//传递一个const char* 类型的ASCII字符“Welcome”,会调用QString的构造函数
str1 = str1 + " to you!";
qDebug()<< str1;
方式2:
QString str1 = "Welcome";
QString str2 = " to";
str1.append(str2);
str1.append(" you!");
qDebug()<< str1;
方式3:
QString str;
str.sprintf("%s"," Welcome");
qDebug()<< str;
str.sprintf("%s"," to you!");
qDebug()<< str;
str.sprintf("%s %s","Welcome"," to you!");
qDebug()<< str;
QString str;
方式4:
str = QString("%1 was born in %2").arg("John").arg(1988);
qDebug()<< str;
方式5:
str.insert(1,"IS ");//在指定位置插入字符串
str.prepend("ABC ");//在字符串开头位置插入字符串
qDebug()<< str;