续写文本到文件
使用标记QFile::WriteOnly| QIODevice::Append打开文件
QString strConfigFile = "C:\\Users\\xiaosheng\\Desktop\\Log.txt";
QFile file1(strConfigFile);
QString strLog2;
strLog2 += "strKeyId" + "\n";
if (file1.open(QFile::WriteOnly| QIODevice::Append))
{
QString strTempXml = strLog2;
QTextStream out(&file1);
out.setCodec("UTF-8");
out << strTempXml;
file1.close();
}
覆盖文本到文件
使用标记QFile::WriteOnly打开文件
QString strConfigFile = "C:\\Users\\xiaosheng\\Desktop\\Log.txt";
QFile file1(strConfigFile);
QString strLog2;
strLog2 += "strKeyId" + "\n";
if (file1.open(QFile::WriteOnly))
{
QString strTempXml = strLog2;
QTextStream out(&file1);
out.setCodec("UTF-8");
out << strTempXml;
file1.close();
}