做了一个串口接收小软件,接收电压和温度,通讯和显示都正常,现在要增加一个定时保存的功能,每秒存一次接收的数据,写到txt文件中,我知道要用到QTimer,QFile,QTextStream这些,我在网上查到的都是手动存储一次的方法,比如:
QString tempData=ui->txtDataHex->toPlainText();    
 if (tempData==""){return;}//如果没有内容则不保存
 QDateTime now=QDateTime::currentDateTime();   
 QString name=now.toString("yyyyMMddHHmmss");   
 QString fileName=name+".txt";
 QFile file(fileName);    
 file.open(QFile::WriteOnly | QIODevice::Text | QIODevice::Append);   
 QTextStream out(&file);    
 out << tempData << "\r\n";
 file.close();而我的是要不停循环存储,不知道怎么写代码了。总不能每秒创建一个文件吧,请大神指点。