It works once, but crashes if I do it again
I call this code on the startup of the application, but if I call it again, it crashes without any errors.
Code:
void MCM::repopWList()
{
mcDir.cd("saves");
backupsDir.cd("MCM/backups");
mcDir.
setFilter(QDir::Dirs |
QDir::NoDotAndDotDot);
backupsDir.
setFilter(QDir::Dirs |
QDir::NoDotAndDotDot);
ui->worldList->clear();
//list the worlds
QFileInfoList mcDirList = mcDir.entryInfoList();
for (int i = 0; i < mcDirList.size(); i++) {
ui->worldList->addItem(fileInfo.fileName());
}
QFileInfoList backupsDirList = backupsDir.entryInfoList();
for (int i = 0; i < backupsDirList.size(); i++)
{
bool wExist = false;
for (int j = 0; j < ui->worldList->count(); j++)
{
string itemText = ui->worldList->item(j)->text().toStdString();
if (itemText == backupInfo.fileName().toStdString())
{
wExist = true;
}
}
if (wExist == false)
{
QString newWorld
(backupInfo.
fileName());
ui->worldList->addItem(newWorld);
}
}
}
Re: It works once, but crashes if I do it again
Have you run it in your debugger and looked at the backtrace you get when it crashes? What line causes the crash?
Re: It works once, but crashes if I do it again
I get EXC_BAD_ACCESS
caused by
Code:
ui->worldList->clear()
Re: It works once, but crashes if I do it again
Is ui->worldList a valid pointer? Have you deleted (or called deleteLater()) on the list at any time? Does any other part of your program hold a pointer to any QListWidgetItem in the list?