Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Deleting folder results in application crash
Qt 6.11 is out! See what's new in the release blog

Deleting folder results in application crash

Scheduled Pinned Locked Moved General and Desktop
qdir
1 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    testus
    wrote on last edited by testus
    #1

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved