QFile *file = new QFile(QDir::currentPath() + "/log.txt");
file->open(QIODevice::WriteOnly);
for (int i = 0; i < 9999; i++)file->write("Test\r\n");
file->open(QIODevice::WriteOnly);
for (int i = 0; i < 9999; i++)file->write("Test\r\n");
file->close();
QString write2fileName; //写读取的串口数据到该文件
if(!write2fileName.isEmpty()){
QFile file(write2fileName);
//如果打开失败则给出提示并退出函数
if(!file.open(QFile::WriteOnly | QIODevice::Text)){
QMessageBox::warning(this, tr("写入文件"), tr("打开文件 %1 失败, 无法写入\n%2").arg(write2fileName).arg(file.errorString()), QMessageBox::Ok);
return;
}
QTextStream out(&file);
out<<buf;
file.close();
}