I call this code on the startup of the application, but if I call it again, it crashes without any errors.

Qt Code:
  1. void MCM::repopWList()
  2. {
  3. QDir mcDir = QDir(McFolder);
  4. QDir backupsDir = QDir(McFolder);
  5. mcDir.cd("saves");
  6. backupsDir.cd("MCM/backups");
  7. mcDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
  8. backupsDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
  9.  
  10. ui->worldList->clear();
  11.  
  12. //list the worlds
  13. QFileInfoList mcDirList = mcDir.entryInfoList();
  14. for (int i = 0; i < mcDirList.size(); i++) {
  15. QFileInfo fileInfo = mcDirList.at(i);
  16. ui->worldList->addItem(fileInfo.fileName());
  17. }
  18. QFileInfoList backupsDirList = backupsDir.entryInfoList();
  19. for (int i = 0; i < backupsDirList.size(); i++)
  20. {
  21. bool wExist = false;
  22. QFileInfo backupInfo = backupsDirList.at(i);
  23. for (int j = 0; j < ui->worldList->count(); j++)
  24. {
  25. string itemText = ui->worldList->item(j)->text().toStdString();
  26. if (itemText == backupInfo.fileName().toStdString())
  27. {
  28. wExist = true;
  29. }
  30. }
  31. if (wExist == false)
  32. {
  33. QString newWorld(backupInfo.fileName());
  34. ui->worldList->addItem(newWorld);
  35. }
  36. }
  37. }
To copy to clipboard, switch view to plain text mode