QPixmap.loadFromData(...) fails for a valid PNG



  • QPixmap.loadFromData(...) fails when trying to load a PNG from a byte array retrieved from a database. The PNG appears valid because after writing the bytes to a file it opened correctly in a PNG viewer.

    The code is as follows:

    pixmapReturn.loadFromData((const uchar *)diagram.c_str(),strlen(diagram.c_str()),"PNG");



  • If you dump it to a file like in your test, but then load it with QPixmap::load() does it work?


  • Lifetime Qt Champion

    Hi,

    What class is diagram ?

    My guess is that strlen doesn't return what you expect. That function returns the length of a string which is determined by the terminating null-character. The binary data of an image can contains myriads of null-character.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.