PDA

View Full Version : Problem with QList



Gargolissimus
3rd July 2009, 10:38
Hello,
if im using a QList for images, images contains a null pointer after each iteration of the loop. It works fine with QLinkedList or QVector.
Why?


QStringList::iterator i = files.begin();
while (i != files.end()) {
QImage img(*i);
images << img;
i++;

}
thanks
Garg

wysota
3rd July 2009, 11:07
What null pointer?

Gargolissimus
3rd July 2009, 11:59
E.g. there are 2 files, after iterating threw the while-loop...

QList:
...images contain two elements of type QImage, but they are 0x00000000.


QVector:
...images contain two elements of type QImage, but their adresses are valid locations.

Here an image of my vs debug output:
http://www.vxr.de/images/foo.jpg

wysota
3rd July 2009, 12:08
What does img.isNull() return in both cases?

Gargolissimus
3rd July 2009, 12:30
false in both cases.. hmmm

wysota
3rd July 2009, 13:12
Is the code you posted the exact code you use?

Gargolissimus
3rd July 2009, 13:32
void CodebookCreator::loadImages(QString &dir, QStringList &files)
{
QDir::setCurrent(dir);
QStringList::iterator i = files.begin();
while (i != files.end()) {
if (QFile::exists(*i)) {
QImage img(*i);
images << img;
i++;
} else {
QMessageBox::warning(0, "Datei nicht gefunden",
"Datei " + *i + " konnte nicht geladen werden.");
i++;
}
}
}

thats it.

only the header file differs.


QList<QImage> images;


QVector<QImage> images;

wysota
3rd July 2009, 15:01
And it works with vector but not with a list?

Gargolissimus
6th July 2009, 16:24
I tested it again. It works with both, i just misinterpreted the debug output ... i'm not very experienced with my IDE, sorry for that.

br
Garg