[Qt-interest] QHash for QImage

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Feb 17 12:43:02 CET 2010


Agus Syawal wrote on Wednesday, February 17, 2010 11:33 AM:

> ... The buffer is QHash<int, QImage>
> type.  
> So here I have a for loop:
> 
> for (i = startPage; i < endPage; i++) {
>    buffer.insert(startPage, poppler->getImage(startPage)); }

So given the declaration of your QHash, I take it that poppler->getImage returns a QImage value, is that correct?

> In several case, I found that buffer.contains(page) return TRUE, but
> the Image I got from buffer.value(page) is a null image. 

When you say "null image", I understand you really mean QImage::isNull() returns true, right?

Anyway, since you are inserting a *value* into your QHash, buffer.contains(page) would *always* return true, regardless of whether the QImage is a "null" image or not! contains() merely checks whether you have inserted a QImage with the given key ('page'), but the actual state of QImage is of no concern to the method QHash::contains().

> I put some
> debug statement before I put the image into buffer, and it is not
> null.  

Again I take it you test for QImage::isNull().

> But when I try to get the image from buffer, sometimes it returns
> null image.

So you are saying the value of QImage::isNull() changes before and after you insert it into your QHash? If that was the case, that would be a bug, but I don't think that is the case (since QHash is used extensively by other people which would have noticed such a thing a long time ago). Unless you modify your QImage yourself.
 
So are you sure you don't mean something like QHash<int, QImage *>? (In this case it would be a question about "who owns the QImage objects" and what happens with them after poppler->getImage() returns).

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list