方法1:QFileSystemWatcher
//connect信号和槽
fileWatcher = new QFileSystemWatcher();
bool flag = connect(fileWatcher,SIGNAL(fileChanged(QString)),this,SLOT(slot_VideofileUpdated(QString)));
//添加文件监测
fileWatcher->addPath(info.video); //短时间一直在变只会最后一次发送change信号 监测到保存结束再emit post信号
void MainWindow::slot_VideofileUpdated(QString path)
{
qDebug()<<"保存完毕:"<<path;
//"E:/PROject/Qt/new1008/ProCocaCola/saveVideo/2021-11-05 18:29:17_河北_秦皇岛_燕山大学_信息管314_Vest_ID:001.mp4"
fileWatcher->removePath(path);
//监测到视频文件已经存储完毕
}
方案2:修改时间比较
bool MyThread::isSavedSucceed(QString path)
{
QFileInfo fileInfo = QFileInfo(path);
int index = fileInfo.lastModified().msecsTo(QDateTime::currentDateTime());
if(index > 1000) //超过1秒表示存储完成
return true;
else
return false;
}