Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPixmap.loadFromData(...) fails for a valid PNG

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    duckman
    wrote on last edited by
    #1

    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");

    1 Reply Last reply
    0
    • Chris HennesC Offline
      Chris HennesC Offline
      Chris Hennes
      wrote on last edited by
      #2

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

      Chris Hennes, Pioneer Library System

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved