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. [SOLVED] Images not loading with QImage.load
Forum Update on Tuesday, May 27th 2025

[SOLVED] Images not loading with QImage.load

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 10.6k 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.
  • Y Offline
    Y Offline
    yalnte
    wrote on last edited by
    #1

    Hi,

    I'm trying to load an image file into a QImage using the function:

    @
    backgroundImage.load(myImageFileName)
    @

    I've tried PNG, JPG and BMP files but none of them work (the function returns 'false').

    I tried to debug this by using the QImageReader:

    @
    QImageReader myImage(imageFileName.c_str());
    myImage.read(&backgroundImage);
    qDebug() << myImage.error();
    qDebug() << myImage.errorString();
    @

    This returns:
    "0"
    "Unknown error"

    I've tried listing the supported image formats
    @qDebug() << QImageReader::supportedImageFormats();@

    and this gives:

    ("BW", "EPS", "EPSF", "EPSI", "EXR", "PCX", "PSD", "RAS", "RGB", "RGBA", "SGI", "TGA", "XCF", "bmp", "bw", "dds", "eps", "epsf", "epsi", "exr", "gif", "ico", "jp2", "jpeg", "jpg", "mng", "pbm", "pcx", "pgm", "pic", "png", "ppm", "psd", "ras", "rgb", "rgba", "sgi", "svg", "svgz", "tga", "xbm", "xcf", "xpm", "xv")

    Does anyone have any ideas please? I've copied the image plugins into a directory named 'plugins' in the same directory as the executable.

    Thanks in advance.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Which platform?

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yalnte
        wrote on last edited by
        #3

        OpenSUSE Linux 11.4 - I've tried using the full path and relative addressing (i.e. Just the filename)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          If that list of supported formats comes from the deployed system (not your dev system) then there's no reason for the image load to fail unless the image files are corrupt or missing.

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yalnte
            wrote on last edited by
            #5

            Thanks - I have versions of this on the dev and deployed system and both give the same error.

            Extra things I've tried (to no avail) are:

            • different pictures and filetypes (JPG & PNG)
            • selecting the file using QFileDialog::getOpenFileName() to ensure file path correct
            • Trying backgroundImage=myImage.read() instead of myImage.read(&backgroundImage);

            One new message I've seen is:

            @kfilemodule(27138)/kio (KDirModel) KDirModelPrivate::_k_slotDeleteItems: No node found for item that was just removed: KUrl("file:///home/yalnte/testpic1.png")@

            Is this related?

            The problem must be due to something silly - I might have to leave this and then come back to it another time with fresh eyes.

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yalnte
              wrote on last edited by
              #6

              I Rewrote this bit of code from scratch and it now works. Not sure what problem was exactly, but believe there was some kind of garbled conversion between std::string, QString and a c_str version of Filename. Thanks for your help.

              1 Reply Last reply
              0

              • Login

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