//从文件加载英文属性与中文属性对照表
QFile file(":/propertyname.txt");
if (file.open(QFile::ReadOnly)) {
//QTextStream方法读取速度至少快百分之30
#if 0
while(!file.atEnd()) {
QString line = file.readLine();
appendName(line);
}
#else
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
appendName(line);
}
#endif
file.close();
}
Qt|将QString字符串写入文件中
void writeFile(const QString str)
{
QFile file;
file.setFileName("./log.txt");
//只写 追加写入
if(file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::append))
{
QTextStream in(&file);
in<<str<<endl;
}
file.close();
}
String和QString之间的转化
QString qstr;
string str;
str = qstr.toStdString();
qstr = QString::fromStdString(str);