[Qt-interest] Fwd: QCache accessing problem

Nathan Carter nathancarter5 at gmail.com
Sat Jun 6 03:04:36 CEST 2009


Yuvaraj,

I am forwarding this to the list.  As I said in my last email, it is  
not customary nor polite to reply off-list.  I like to teach, but I am  
not your personal Qt tutor.  If you want help from the list, ask  
questions in a way that is likely to get you answers, and that follows  
rules of net etiquette.
	http://catb.org/esr/faqs/smart-questions.html

Nathan


On Jun 5, 2009, at 4:52 PM, Yuvaraj R wrote:

> Dont mistake me ,I am getting errors ...please help me
>
>
> My download function is
>
> void ImageDownload::request(int id, bool error)
> {
> if(error) return;
> if(http_id == id && http->lastResponse().statusCode() == 200)
> {
> QPixmap *image1 = new QPixmap();
> QByteArray imagedata = buffer->data();
> if(image1->loadFromData(imagedata))
> {
> requestByEntry.key( id );
> Widget w;
> w.getimage(requestByEntry.key( id ),image1);
> }
> buffer->close();
> }
> }
>
> Receiving image function:
>
> void Widget::getimage(QString string,QPixmap image)
> {
> if(!image->isNull())
> {
> if(!imageCache.contains(string))
> {
> qDebug() << "image got";
> QString yu = "singh";
> QString str = string;
> imageCache.insert(str,*image);
>
> }
> }
> }
>
> Is it correct to insert the images into Qcache table
>
>
> Thanks
>
>
>
>
>
> On Sat, Jun 6, 2009 at 1:29 AM, Nathan Carter  
> <nathancarter5 at gmail.com> wrote:
>
> 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
>>
>
>
> _______________________________________________
> 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/cdc225b5/attachment.html 


More information about the Qt-interest-old mailing list