I have a problem on a project im working on. What I want to do is fetching a image from a folder on a web server, and store them as a QPixmap object. Everything goes fine, and the image can be set inside the function which loads the data from the bytearray. But the QPixmap object as defined in the header file, won't hold the data for later use.

Header file:
Qt Code:
  1. #ifndef HTTPBILDE_H
  2. #define HTTPBILDE_H
  3.  
  4. #include <QBuffer>
  5. #include <QHttp>
  6. #include <QUrl>
  7. #include <QPixmap>
  8. #include <QPushButton>
  9.  
  10. class HttpBilde : public QObject {
  11. Q_OBJECT
  12.  
  13. public:
  14. HttpBilde(QString adresse);
  15. ~HttpBilde();
  16.  
  17. public slots:
  18. void finished(int requestId, bool error);
  19.  
  20. signals:
  21. void getPixmap(QPixmap);
  22.  
  23. private:
  24. QBuffer *buffer;
  25. QByteArray bytes;
  26. QHttp *http;
  27. int Request;
  28. QUrl url;
  29. QPixmap img;
  30. };
To copy to clipboard, switch view to plain text mode 

Cpp file:
Qt Code:
  1. }// constructor
  2. ...
  3. url.setUrl(adresse);
  4. http = new QHttp(this);
  5. buffer = new QBuffer(&bytes);
  6.  
  7. buffer->open(QIODevice::WriteOnly);
  8. http->setHost(url.host());
  9. Request=http->get(url.path(),buffer);
  10.  
  11. connect(http, SIGNAL(requestFinished(int, bool)),this, SLOT(finished(int, bool)));
  12. }
  13.  
  14. }
  15.  
  16. void HttpBilde::finished(int requestId, bool error) {
  17. if (Request==requestId){
  18. img.loadFromData(bytes);
  19. // here I can do whatever i like with the QPixmap (img) and i get correct image data
  20. }
  21. }
  22.  
  23. QPixmap HttpBilde::getPixmap() {
  24. return img;
  25. // The returned QPixmap gets size -1,-1 no pixmap data
  26. }
To copy to clipboard, switch view to plain text mode 

If i send a signal from void HttpBilde::finished(int requestId, bool error) to a slot in another class, the correct pixmap data is sent. And I can set the pixmap to for example a QLabel. But i encounter the same problem in the other class if I try to store it in a QPixmap object in that class.

I have also tried deep copy with no luck. It holds the data as long as it gets emited trough signals but disappears afterwards.