PDA

View Full Version : Index out of Range



santhoshv84
19th August 2008, 10:52
Hi Friends,

I am getting an error 'Index out of Range' in this program



QDir dir(ImagesDirPath);
dir.setFilter(QDir::Files | QDir::NoSymLinks);
QStringList filters;
filters << "*.xml";
dir.setNameFilters(filters);
dir.setSorting(QDir::Name);

QStringList Strlist;
QFileInfoList list = dir.entryInfoList();

for (int i = 0; i < list.size(); ++i)
{
QFileInfo fileInfo = list.at(i);
Strlist<<fileInfo.baseName();
}

ui.comboBox_2->insertItems(0,Strlist);

How to solve this?

Thanks in Advance..

roxton
19th August 2008, 11:28
try this:


for (int i = 0; i < list.size() - 1; ++i)
{
QFileInfo fileInfo = list.at(i);
Strlist<<fileInfo.baseName();
}

//i.e. list.size() - 1

caduel
19th August 2008, 15:33
try to avoid indexing when you do not need it:

QStringList l;
foreach (const QFileInfo &fi, dir.entryInfoList())
l << fi.baseName();


PS: "< list.size()" should be correct.
Have you tried using a debugger to find the line that causes the crash?

HTH