Results 1 to 3 of 3

Thread: QByteArray to QPixmap

  1. #1
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QByteArray to QPixmap

    Hello everybody

    I've a network request that returns a jpeg image. But I get the data as raw QByteArray. How can I convert the QByteArray into a QPixmap?

    The requestFinished(QNetworkReply *pReply) slot shown below is connected to the signal void finished(QNetworkReply *) of QNetworkManager.

    Qt Code:
    1. void NetworkManagement::requestFinished(QNetworkReply *pReply) {
    2. if (!pReply->error()) {
    3.  
    4. // I need the pixmap to show it in a list view (decoration role)
    5. QPixmap pixmap(pReply->readAll());
    6.  
    7. // I try to save the pixmap as a jpg file to the disk.
    8. bool result = pixmap.save("test.jpg", "jpg");
    9. // This fails, Don't know why.
    10. Q_ASSERT(result);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    Any advice?

    Thanks!
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray to QPixmap

    You probably need to use QPixmap::loadFromData().
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray to QPixmap

    Thanks It worked this way!
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

Similar Threads

  1. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 08:23
  2. Replies: 9
    Last Post: 25th July 2009, 13:27
  3. QByteArray into QPixmap
    By yagabey in forum Qt Programming
    Replies: 10
    Last Post: 12th February 2008, 22:19
  4. Replies: 5
    Last Post: 9th April 2007, 14:26
  5. QPixmap from QByteArray.
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 8th July 2006, 15:37

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.