PDA

View Full Version : QCachece accessing problem



rajini333
5th June 2009, 14:05
When accessing the QCache that time my application is crashing...

Just i downloaded one image and inserted into QCache table.

Then i am getting some downloaded images from other class and inserted in QCache table.

Now i am trying to access the QCache table using Keys(URL link).. That time application is crashing ,even the corresponding key values is in tables also...

if i access the first images,what i stored from this class only..That image i am getting ..

When accessing the another class images,which is stored in QCache..that time application is crashing..

Code for downloading the image at same class


void Widget::imageGet( const QString url )
{
static int i =0;
i++;
qDebug() << i;
if(!imageCache.contains(url))
{
QPixmap yu;
imageCache.insert(url,NULL);
QUrl _url = QUrl(url);
buffer->open(QIODevice::ReadWrite);
qDebug() << "url link is " << url;
http->setHost(_url.host());
qDebug() << "not same url";
http_id = http->get(_url.path(), buffer);
requestByEntry.insert(url,http_id);
}
}
void Widget::request(int id, bool error)
{

if(error) return;
if(http_id == id && http->lastResponse().statusCode() == 200)
{
QPixmap image ;
QByteArray imagedata = buffer->data();
image.loadFromData(imagedata);

imageCache.insert(requestByEntry.key(id),&image);
ui->userpiclabel->setPixmap(*imageCache[URL]);
QPixmap yu;
yu = *imageCache[URL];

QString str ="yuvaraj";
QString str1 ="text";
Tweet *f = new Tweet(str,str1,yu);
buffer->close();
}
}


Getting images from other class . I checked this images is not null



void Widget::getimage(QString string,QPixmap image)
{
if(!image.isNull())
{
if(!imageCache.contains(string))
{
qDebug() << "image got";
imageCache.insert(string,&image);

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

}
}
}

Accessing the images from QCache


void Widget::DisplayList(QLinkedList<Returnables::StatusUser*> list, QString header)
{
Returnables::StatusUser *statusUser = NULL;
model = new QStandardItemModel(this);
for(int i=0;i<list.size();i++)
{ QStandardItem *item = new QStandardItem;
model->appendRow(item);
}
qDebug() <<" Running at second for loop";
ui->listView_2->setModel(model);
static int j = list.size();

for(int i=0;i<j;i++)
{

qDebug() <<"Hello friends";
statusUser = list.takeFirst();
QString url =statusUser->user.profileImageUrl;
QString name = statusUser->user.name;
QString text = statusUser->status.text;
qDebug() << "imageCache size :" <<imageCache.size();
qDebug() << url ;
if(imageCache[url] == NULL)
{

QPixmap rr;
// qDebug()<<"image null";
rr = *imageCache[URL];
qDebug()<<"image null0";
qDebug() << "hi hello";
Tweet *t =new Tweet(name,text,rr);
t->resize(490,90);
model->item(i)->setSizeHint(t->size());
ui->listView_2->setIndexWidget(model->item(i)->index(), t);
qDebug()<<"i Am for loop";
}
if(imageCache[url] != NULL)
{
QString url1 = statusUser->user.profileImageUrl;
qDebug() << url;
qDebug()<<"image is not null";
qDebug() << imageCache.keys();
qDebug() << "url link:"<< url1;
QPixmap yy;
yy = *imageCache.take(url);
qDebug() << "image assigned";
Tweet *t =new Tweet(name,text,yy);
t->resize(490,90);
model->item(i)->setSizeHint(t->size());
ui->listView_2->setIndexWidget(model->item(i)->index(), t);

}
}
}



when compiler is coming at line of assigning the images from image Cache[url] that time application is crashing...

I hope some one might help us


Thanks

Yuvaraj R

wysota
5th June 2009, 19:15
Creating three different users at the forum is not a very good idea if you want people to help you. This tends to make some of us annoyed...

As for the question - you are storing a pointer to a local object in the cache. Hence when the object runs out of scope you end up with an invalid pointer which you try to access later on.