#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str;
if(str.isNull())
{
qDebug()<<"isNull"<<endl;
}
if(str.isEmpty())
{
qDebug()<<"isEmpty"<<endl;
}
str = "";
if(str.isNull())
{
qDebug()<<"isNull2"<<endl;
}
if(str.isEmpty())
{
qDebug()<<"isEmpty2"<<endl;
}
QString str2;
//最优:无需判断是否进行初始化
if(str2 == "")
{
qDebug()<<"str2 isNULL"<<endl;
}
QString str3 = "test1";
str3 += "test2";
str3 += 'A';
str3.append("test3");
qDebug()<<str3;
QString str4("test4");
qDebug()<<str4;
return a.exec();
}
版权声明:本文为chengfenglee原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。