Deleting folder results in application crash



  • Everytime I call QDir::removeRecursively() my application crashes AFTER having removed the folder containing the files correctly.
    Having done some testing I found out that it depends on how I call the function. This is my code:

    Recorder::Recorder(ParentClass *parent): QObject(parent){
    	
    	 connect(this,SIGNAL(finishedRec(QString,QString)),this,SLOT(finishedRecording(QString,QString)));
    }
    
    void Recorder::start(){
    	if (!recording){
                        recording=true;
    		recThread.reset(new std::thread(&Recorder::recordThread, this));
    	}
    }
    
    void Recorder::stop(){
    	recording = false;
    	recThread->join(); recThread.reset();
    }
    void Recorder::recordThread(){
    	QString picDir;
    	QString filename;
    	//....
    	while(recording){
    		//writing frames to folder
    	}    
    	emit finishedRec(picDir,filename);    
    }
    
    void Recorder::finishedRecording(QString picDir, QString filename){
    	QProcess* proc = new QProcess();
    	vecProcess.append(proc);
    	vecString.push_back(picDir);
    	proc->start("C:\\ffmpeg.exe", QStringList() <<"-i"<< picDir << "-r"<< "30" << "-vcodec"<< "ffv1" << filename);
    	connect(proc,SIGNAL(finished(int)),this,SLOT(finishedProcess()));
    }
    
    void Recorder::finishedProcess(){
    	for (int i=0; i<vecProcess.size();i++){
    		if(vecProcess.at(i)->state()==QProcess::NotRunning){
    			delete vecProcess.at(i);
    			vecProcess.erase(vecProcess.begin() + i);
    
    			QString folderToRemove=vecString.at(i);
    			folderToRemove.chop(12);
    			qDebug() << folderToRemove;
    			QDir dir(folderToRemove);
    			dir.removeRecursively();
    			vecString.erase(vecString.begin() + i);
    
    		}
    	}
    }
    

    Only if I leave dir.removeRecursively() in, my application will always crash. Without it everything works as intended. Even deleting all the files with

    QDir dir(path);
    dir.setNameFilters(QStringList() << "*.*");
    dir.setFilter(QDir::Files);
    foreach(QString dirFile, dir.entryList()){
    	dir.remove(dirFile);
    }
    

    will cause a crash AFTRER all the files were deleted.

    Calling removeRecursively() in a different event loop works. Why doesn't it work when using it in a SLOT like shown in my example?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.