[Qt-interest] Fwd: QCache accessing problem

Nathan Carter nathancarter5 at gmail.com
Fri Jun 5 21:59:38 CEST 2009


Dear Yuvaraj,

You should reply to the list, so that everyone sees the conversation,  
and so do the archives.

I was guessing about what your problem might be, and I think you need  
to go to check to see if my guess is correct.  Look at the place in  
your code where you call getImage(), and see what you're passing as  
the second parameter.  Is it a variable you declare on the stack, like  
this

	QPixmap foo;

or a variable you declare on the heap, like this

	QPixmap* foo = new QPixmap();

?  If it's the first way, then your pixmap will be deleted as soon as  
the function in which it is declared exits.  In this case, any pointer  
to it will be invalid, like the pointer you're storing in the cache.

But this is C++, not Qt, so I don't think we should go too much  
farther down this road on the Qt list.

Nathan


On Jun 5, 2009, at 3:56 PM, Yuvaraj R wrote:

>
> Thanks
>
>  I don't have much more experience. I am  a Beginner .
>
> How do solve this issue..
>
>
> please give me  the suggestions..
>
>
>
> On Sat, Jun 6, 2009 at 12:19 AM, Nathan Carter <nathancarter5 at gmail.com 
> > wrote:
>
> > void Widget::getimage(QString string,QPixmap image)
> > {
> > if(!image.isNull())
> > {
> > if(!imageCache.contains(string))
> > {
> > qDebug() << "image got";
> > QString yu = "yuvaraj";
> > imageCache.insert(string,&image);
> > qDebug() << "Hash Table size:" << imageCache.size();
> > }
> > }
> > }
>
> Is it possible that you're inserting &image into the cache, but the
> caller of this has image allocated on the stack, and thus destroys it
> shortly after calling getImage()?  Just guessing, based on the fact
> that you're passing in the QPixmap by value.
>
>
>
> Nathan
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090605/b2bfb235/attachment.html 


More information about the Qt-interest-old mailing list