[Qt] 监测文件是否读写完毕 避免还未保存完毕就被操作

方法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;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值