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. Can not convert A QByteArray to QImage on windows7
Forum Updated to NodeBB v4.3 + New Features

Can not convert A QByteArray to QImage on windows7

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 610 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.
  • N Offline
    N Offline
    Neether
    wrote on last edited by
    #1

    QT version 5.13.2

    I read a image file from server,and cast into QImage

    QByteArray filebyte = pReply->readAll();
    QImage current_image = QImage::fromData(filebyte);
    

    It's run success on windows10 and 11
    but on windows7,I get an empty QImage
    I just output the QByteArray into a file,and this file can normally opened as a image

    And I trid to use QImageReader to figure out what happened

     QImageReader reader(filebyte);
     MTLOG_INFO << QStringLiteral("Image conversion failed. Error::%1").arg(reader.errorString()); // just do some log
    

    the error message is Image conversion failed. Error::File not found

    Any god like developer can help me? I‘m alreay reach the deadline

    Christian EhrlicherC 1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      First of all, please consider upgrading to Qt 6. Qt 5.13 is EOL and out of support. I haven't got a copy of it and my answer is based on Qt 6.

      I can just guess what the first problem is, but it looks as if filebyteis emply, or the image reader can't guess the format.
      Try debugging the output of QImageReader::supportedFormats(). Check if your image format is still supported. Try setting it explicitly by using e.g. QImage::fromData(filebyte, "image/png").

      The image reader attempt wouldn't compile in Qt 6, because the used constructor expects a file name as a QString. There is no (more) constructor of QString taking a byte array, but maybe in 5.13 there was one. I don't know.
      In any case, the constructor of the image reader takes a QIODevice *, e.g. a file and a format. In Qt 6, there is no constructor taking a plain byte array with data.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #3

        Hi, @Axel-Spoerl : upgrading to Qt6 makes it much more difficult to run the app on Windows 7, so maybe in this case Qt5 is a better choice,
        @Neether : Window 7 does not support as many different file formats as Windows 10 and 11 do, try changing from .jpg to .png format.

        1 Reply Last reply
        0
        • N Neether

          QT version 5.13.2

          I read a image file from server,and cast into QImage

          QByteArray filebyte = pReply->readAll();
          QImage current_image = QImage::fromData(filebyte);
          

          It's run success on windows10 and 11
          but on windows7,I get an empty QImage
          I just output the QByteArray into a file,and this file can normally opened as a image

          And I trid to use QImageReader to figure out what happened

           QImageReader reader(filebyte);
           MTLOG_INFO << QStringLiteral("Image conversion failed. Error::%1").arg(reader.errorString()); // just do some log
          

          the error message is Image conversion failed. Error::File not found

          Any god like developer can help me? I‘m alreay reach the deadline

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Neether said in Can not convert A QByteArray to QImage on windows7:

          QByteArray filebyte = pReply->readAll();

          what is pReply?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          N 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @Neether said in Can not convert A QByteArray to QImage on windows7:

            QByteArray filebyte = pReply->readAll();

            what is pReply?

            N Offline
            N Offline
            Neether
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            it's QNetworkReply,I request a image from remote server

            Christian EhrlicherC 1 Reply Last reply
            0
            • N Neether

              @Christian-Ehrlicher
              it's QNetworkReply,I request a image from remote server

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Neether And you read it after requestFinished()?
              I would save it to a file and try to read it with another image reader. Also make sure the Qt jpeg image plugin is available on your system. (plugins/imageformats folder in your Qt installation).

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1

              • Login

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