Reputation: 113
I have a process being called by a QProcess*. After creation, I'm connecting its finished() signal to a slot that deletes some resulting files. This process creates a set of files that are well-known at execution time. I'm creating a QFile* object for each one of them. I'm trying to delete those files after that specified process has finished.
The problem is: if I try to delete them with QFile::remove() or QDir::remove(), nothing seems to happen. If I try to rename them, though, it renames, but before the process has finished - even though its finished signal has been emitted. Also, QDir::removeRecursively() deletes them. I tried to create a new directory, move the files to that folder and use Qdir::removeRecursively() - and even deleted all my desktop -, but, as I said, the "delete files" slot is being called before the process has really finished. I tried to use QProcess::waitForFinished() to prevent this premature call, but it didn't work.
By the way, I'm asking the user where to save the files, so they can be saved anywhere when I try to delete them. Also, I cannot ask for admin privileges.
Thank you!
QProcess call
QProcess *execute_call = new QProcess(this);
execute_call->setWorkingDirectory(lastSavingLocation + "/control/");
execute_call->setProgram(execute_call->workingDirectory() + "execute.bat");
connect(execute_call, SIGNAL(finished(int)), this, SLOT(DeleteExecutionFiles(int)));
execute_call->start();
execute_call->waitForFinished(-1);
//I tried to put this
//before the start() call, but nothing seems to change
DeleteFiles Slot
void MainWindow::DeleteExecutionFiles(int status)
{
if(status == 0)
{
qDebug() << "slot called";
QFile *lof_mh = new QFile(lastSavingLocation + "/lof-mh.exe");
QFile *libgomp = new QFile(lastSavingLocation + "/libgomp-1.dll");
QFile *libwin = new QFile(lastSavingLocation + "/libwinpthread-1.dll");
QFile *tests_env = new QFile(lastSavingLocation + "/control/lof-mh-testenvironment-tool.exe");
QFile *execute = new QFile(lastSavingLocation + "/control/execute.bat");
QFile *execute_bat = new QFile(lastSavingLocation + "/control/executeParallel.bat");
lof_mh->setFileName(lastSavingLocation + "/lof-mh.exe");
libgomp->setFileName(lastSavingLocation + "/libgomp-1.dll");
libwin->setFileName(lastSavingLocation + "/libwinpthread-1.dll");
tests_env->setFileName(lastSavingLocation + "/control/lof-mh-testenvironment-tool.exe");
execute->setFileName(lastSavingLocation + "/control/execute.bat");
execute_bat->setFileName(lastSavingLocation + "/control/executeParallel.bat");
lof_mh->remove();
libgomp->remove();
libwin->remove();
tests_env->remove();
execute->remove();
execute_bat->remove();
}
}
Edit 1
After using qDebug() with QFile::errorString() got this
lof_mh.remove();
qDebug() << lof_mh.errorString(); //"Negated Access"
libgomp.remove();
qDebug() << libgomp.errorString(); //"Negated Access"
libwin.remove();
qDebug() << libwin.errorString(); //"Negated Access"
tests_env.remove();
qDebug() << tests_env.errorString(); //"Negated Access"
execute.remove();
qDebug() << execute.errorString(); //"Unknown Error"
execute_bat.remove();
qDebug() << execute_bat.errorString(); //"Unknown Error"
Upvotes: 0
Views: 3554
Reputation: 113
I managed to delete the files changing the permission of the files with:
lof_mh.setPermissions(QFileDevice::WriteUser | QFileDevice::ReadUser | QFileDevice::ExeUser);
libgomp.setPermissions(QFileDevice::WriteUser | QFileDevice::ReadUser | QFileDevice::ExeUser);
libwin.setPermissions(QFileDevice::WriteUser | QFileDevice::ReadUser | QFileDevice::ExeUser);
tests_env.setPermissions(QFileDevice::WriteUser | QFileDevice::ReadUser | QFileDevice::ExeUser);
execute.setPermissions(QFileDevice::WriteUser | QFileDevice::ReadUser | QFileDevice::ExeUser);
execute_bat.setPermissions(QFileDevice::WriteUser | QFileDevice::ReadUser | QFileDevice::ExeUser);
After that, I deleted them with QFile::remove() just as normal. This brings another problem, though: the DeleteFiles() slot should be called when the finished() signal of the QProcess* is emmited, yet, the slot is called when the proccess is still running, so the files get deleted and it loses track of the files and crash. Anyway, I'll create another post to check for answers specific to this subject.
Thanks to everybody that helped!
Upvotes: 3