Results 1 to 2 of 2

Thread: QCachece accessing problem

  1. #1
    Join Date
    Jun 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QCachece accessing problem

    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
    Qt Code:
    1. void Widget::imageGet( const QString url )
    2. {
    3. static int i =0;
    4. i++;
    5. qDebug() << i;
    6. if(!imageCache.contains(url))
    7. {
    8. QPixmap yu;
    9. imageCache.insert(url,NULL);
    10. QUrl _url = QUrl(url);
    11. buffer->open(QIODevice::ReadWrite);
    12. qDebug() << "url link is " << url;
    13. http->setHost(_url.host());
    14. qDebug() << "not same url";
    15. http_id = http->get(_url.path(), buffer);
    16. requestByEntry.insert(url,http_id);
    17. }
    18. }
    19. void Widget::request(int id, bool error)
    20. {
    21.  
    22. if(error) return;
    23. if(http_id == id && http->lastResponse().statusCode() == 200)
    24. {
    25. QPixmap image ;
    26. QByteArray imagedata = buffer->data();
    27. image.loadFromData(imagedata);
    28.  
    29. imageCache.insert(requestByEntry.key(id),&image);
    30. ui->userpiclabel->setPixmap(*imageCache[URL]);
    31. QPixmap yu;
    32. yu = *imageCache[URL];
    33.  
    34. QString str ="yuvaraj";
    35. QString str1 ="text";
    36. Tweet *f = new Tweet(str,str1,yu);
    37. buffer->close();
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. void Widget::getimage(QString string,QPixmap image)
    2. {
    3. if(!image.isNull())
    4. {
    5. if(!imageCache.contains(string))
    6. {
    7. qDebug() << "image got";
    8. imageCache.insert(string,&image);
    9.  
    10. qDebug() << "Hash Table size:" << imageCache.size();
    11.  
    12. }
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Accessing the images from QCache
    Qt Code:
    1. void Widget::DisplayList(QLinkedList<Returnables::StatusUser*> list, QString header)
    2. {
    3. Returnables::StatusUser *statusUser = NULL;
    4. model = new QStandardItemModel(this);
    5. for(int i=0;i<list.size();i++)
    6. model->appendRow(item);
    7. }
    8. qDebug() <<" Running at second for loop";
    9. ui->listView_2->setModel(model);
    10. static int j = list.size();
    11.  
    12. for(int i=0;i<j;i++)
    13. {
    14.  
    15. qDebug() <<"Hello friends";
    16. statusUser = list.takeFirst();
    17. QString url =statusUser->user.profileImageUrl;
    18. QString name = statusUser->user.name;
    19. QString text = statusUser->status.text;
    20. qDebug() << "imageCache size :" <<imageCache.size();
    21. qDebug() << url ;
    22. if(imageCache[url] == NULL)
    23. {
    24.  
    25. QPixmap rr;
    26. // qDebug()<<"image null";
    27. rr = *imageCache[URL];
    28. qDebug()<<"image null0";
    29. qDebug() << "hi hello";
    30. Tweet *t =new Tweet(name,text,rr);
    31. t->resize(490,90);
    32. model->item(i)->setSizeHint(t->size());
    33. ui->listView_2->setIndexWidget(model->item(i)->index(), t);
    34. qDebug()<<"i Am for loop";
    35. }
    36. if(imageCache[url] != NULL)
    37. {
    38. QString url1 = statusUser->user.profileImageUrl;
    39. qDebug() << url;
    40. qDebug()<<"image is not null";
    41. qDebug() << imageCache.keys();
    42. qDebug() << "url link:"<< url1;
    43. QPixmap yy;
    44. yy = *imageCache.take(url);
    45. qDebug() << "image assigned";
    46. Tweet *t =new Tweet(name,text,yy);
    47. t->resize(490,90);
    48. model->item(i)->setSizeHint(t->size());
    49. ui->listView_2->setIndexWidget(model->item(i)->index(), t);
    50.  
    51. }
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCachece accessing problem

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 6th May 2009, 12:16
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  4. QProcess problem in accessing stdout
    By aruna in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2006, 18:56
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.