[Qt-creator] Fwd: [Qt-interest] Fwd: QCache accessing problem

Yuvaraj R yuvaraj at ongobiz.com
Fri Jun 5 22:28:41 CEST 2009


---------- Forwarded message ----------
From: Yuvaraj R <yuvaraj at ongobiz.com>
Date: Sat, Jun 6, 2009 at 1:46 AM
Subject: Re: [Qt-interest] Fwd: QCache accessing problem
To: qt-creator at trolltech.com



*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);

Form w;

w.set(*imageCache[string]);

Tweet *t = new Tweet(yu,string,*imageCache[string]);

qDebug() << "Hash Table size:" << imageCache.size();

}

}

}

Is it correct to insert the images into Qcache table






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-creator-old/attachments/20090606/a78866db/attachment.html 


More information about the Qt-creator-old mailing list