Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105186

QList iterator will cause crash

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Invalid
    • Affects Version/s: 5.15.12
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      windows
    • Platform/s:
      Windows

      Description

      void ProjectInfos::getFilesInfos(const QString &path){   
          QDir dir(path);   
          auto files = dir.entryInfoList(QDir::NoDotAndDotDot|QDir::Files |QDir::Dirs);   
          auto it = files.begin();   
          QFile record(getTmpPath()+"/"+dir.dirName()+".csv");    if(!record.open(QIODevice::WriteOnly))   
          {        return ;    }   
          QTextStream out(&record);   
          int i = 0;   
          while (i<files.size())
          {        qDebug()<<" file count "<<files.size()  << " index "<<i;      
              //auto info  = files.at(i);       
              auto info  = *it;      
              out<< info.fileName() <<","<<info.size()<<Qt::endl;       
              qDebug()<<info.fileName() ;       
              bool isFile = info.isFile();        
              if(isFile)      
              {            ++it;        
                  ++i;           
                  continue;     
              }    
              QDir subDir(info.absoluteFilePath());    
              auto subFiles = subDir.entryInfoList(QDir::NoDotAndDotDot|QDir::Files |QDir::Dirs);        //files+=subFiles;       
              for(auto info : subFiles)      
              {           
                  files.push_back(info);     
              }     
              qDebug()<<" add files "<<subFiles.size();        ++it;        ++i;    }   
          out.flush();
      }}
      

       code as before ,iterator will be invalid when append other list.then app crashed!

      but when using std list,it's works.

      here is the log for qlist.

       

       

       

      //代码占位符
      void ProjectInfos::getFilesInfos(const QString &path)
      {   
          QDir dir(path);  
          auto files = dir.entryInfoList(QDir::NoDotAndDotDot|QDir::Files |QDir::Dirs).toStdList();   
          auto it = files.begin();   
          QFile record(getTmpPath()+"/"+dir.dirName()+".csv");    if(!record.open(QIODevice::WriteOnly))   
          {       
              return ;   
          }   
          QTextStream out(&record);   
          int i = 0;    
          while (i<files.size()) 
          {       
              qDebug()<<" file count "<<files.size()  << " index "<<i;     
              //auto info  = files.at(i);       
              auto info  = *it;      
              out<< info.fileName() <<","<<info.size()<<Qt::endl;      
              qDebug()<<info.fileName() ;       
              bool isFile = info.isFile();      
              if(isFile)      
              {            ++it;  
                  ++i;          
                  continue;       
              }         QDir subDir(info.absoluteFilePath());   
              auto subFiles = subDir.entryInfoList(QDir::NoDotAndDotDot|QDir::Files |QDir::Dirs).toStdList();       
              //files+=subFiles;        
              
              for(auto info : subFiles)       
              {           
                  files.push_back(info);     
              }        
              qDebug()<<" add files "<<subFiles.size();      
              ++it;      
              ++i;   
          }   
          out.flush();
      }
      

      the code before works right!

       

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            thiago Thiago Macieira
            Reporter:
            zzc116433008 柱超 张
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes