Windows 在QProcess.waitForFinishand和can';不能删除 我在资源文件中有一个VisualC++的可重新分配安装程序exe。文件被提取,移动到%TEMP%,使用QProcess运行,并在进程结束后删除。我遇到的问题是,即使使用升级的
在QProcess.waitForFinishand和can';不能删除 <>我在资源文件中有一个VisualC++的可重新分配安装程序exe。文件被提取,移动到%TEMP%,使用QProcess运行,并在进程结束后删除。我遇到的问题是,即使使用升级的权限,“权限被拒绝”也会导致文件删除失败。这似乎是由于文件仍被某个东西(忙)使用,因为如果在删除之前添加1秒延迟,它就会开始工作Windows 在QProcess.waitForFinishand和can';不能删除 我在资源文件中有一个VisualC++的可重新分配安装程序exe。文件被提取,移动到%TEMP%,使用QProcess运行,并在进程结束后删除。我遇到的问题是,即使使用升级的,windows,qt,Windows,Qt,在QProcess.waitForFinishand和can';不能删除 我在资源文件中有一个VisualC++的可重新分配安装程序exe。文件被提取,移动到%TEMP%,使用QProcess运行,并在进程结束后删除。我遇到的问题是,即使使用升级的权限,“权限被拒绝”也会导致文件删除失败。这似乎是由于文件仍被某个东西(忙)使用,因为如果在删除之前添加1秒延迟,它就会开始工作 QFile vcredistResource2015(":\\data\\vc_redist.x86.exe");
QFile vcredistResource2015(":\\data\\vc_redist.x86.exe");
QString dst2015 = QDir::temp().absolutePath()+"/vc_redist.x86.exe";
vcredistResource2015.copy(dst2015);
QProcess p2015;
p2015.start(dst2015);
p2015.waitForFinished(-1);
//QThread::sleep(1); //this line solves it
QFile rm15(dst2015);
rm15.setPermissions(QFile::ReadOther|QFile::WriteOther);
if (rm15.exists() && rm15.remove()) {
qDebug() << "removed 2015";
}
else {
qDebug() << rm15.errorString(); //Permission denied here
}
QFile vcreditresource2015(“:\\data\\vc\u redist.x86.exe”);
QString dst2015=QDir::temp().absolutePath()+“/vc_redist.x86.exe”;
VCRedisterSource2015.副本(dst2015);
QProcess p2015;
p2015.启动(dst2015);
p2015.等待完成(-1);
//QThread::sleep(1)//这条线解决了这个问题
QFile rm15(2015年);
rm15.setPermissions(QFile::ReadOther | QFile::WriteOther);
if(rm15.exists()&&rm15.remove()){
qDebug()您应该检查QProcess::waitForFinished
@G.M.返回值是否为true如果p2015在尝试删除exe之前被销毁会有什么不同吗?(即,通过使用额外的块)。尽管sleep()修复它表明没有…@FrankOsterfeld我试图将p2015包含在本地作用域{}块,调用.close()和.deleteLater()实际上没有任何作用。您应该检查QProcess::waitForFinished
@G.M.返回值为true如果在尝试删除exe之前销毁p2015会有什么不同吗?(即,通过使用额外的块)。尽管sleep()修复它表明它没有…@FrankOsterfeld我试图将p2015封装在一个本地作用域{}块中,调用.close()和.deleteLater(),但实际上什么也做不了。