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. Qimage::save() fails
Qt 6.11 is out! See what's new in the release blog

Qimage::save() fails

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 6 Posters 6.3k Views 2 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.
  • C Offline
    C Offline
    CleverFish
    wrote on last edited by
    #1

    My code is generating some image in buffer and trying to save to disk using QImage::save() call. But API call returns false and png file doesn't create. It works on WIndows7 though. I am having problem, if I execute the same application on windows 10. Need help on this.

    artwawA 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Is you location where you want to store your image writeable by the application?

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

      C 1 Reply Last reply
      4
      • C CleverFish

        My code is generating some image in buffer and trying to save to disk using QImage::save() call. But API call returns false and png file doesn't create. It works on WIndows7 though. I am having problem, if I execute the same application on windows 10. Need help on this.

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @CleverFish Hi,
        it would be helpful if you could show us the code in question and also told us what Qt are you using and the toolchain.
        For the code please use code blocks.
        Like @Christian-Ehrlicher asked - is the path you're writing to writable for the program? There were changes to permissions between 7 and 10.

        For more information please re-read.

        Kind Regards,
        Artur

        S 1 Reply Last reply
        3
        • Christian EhrlicherC Christian Ehrlicher

          Is you location where you want to store your image writeable by the application?

          C Offline
          C Offline
          CleverFish
          wrote on last edited by
          #4

          @Christian-Ehrlicher I guess so. It's a location where application writes to. Other files like(PDFs) are being copied to same location. I tried to run the Application with elevated user rights(ADMIN) and the result is same. This issue is been consistently seen in windows 10.

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

            Hi,

            Can you share the code you use to save the image ?
            How are you building the path ?

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

            S 1 Reply Last reply
            1
            • artwawA artwaw

              @CleverFish Hi,
              it would be helpful if you could show us the code in question and also told us what Qt are you using and the toolchain.
              For the code please use code blocks.
              Like @Christian-Ehrlicher asked - is the path you're writing to writable for the program? There were changes to permissions between 7 and 10.

              S Offline
              S Offline
              swagat
              wrote on last edited by
              #6

              @artwaw Following is the code, I am having trouble with: I couldn't copy the entire code as thish is a legacy code.

              ProcessTemplate() dose all the paining reading a template file. It does use QWT library to plot graphs.
              QT version: 4.8.6

              /*int ProcessTemplate(QPaintDevice &pDevice, QPainter &painter, PRINT_FORMAT printPDFFormat, QList<RptLine> &printTemplate, int i, QFont & font, QList<QStringList> &newdata, QStringList &cols, QStringList &types, int first, QString &cfgfolderIn, int *iout,QString syncpath)*/
              
              QImage dev(1120 * dpiX / HUNDERDPERCENTDPI_X , 774 * dpiY / HUNDERDPERCENTDPI_Y , QImage::Format_ARGB32);
              ProcessTemplate(dev, jpgPainter, FORMAT_JPG, RPTtemplate, i, font, newdata, cols, types, first, cfgfolderIn, &m,syncpath);
               dev.save(pthj); 
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                What does pthj contain ?

                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
                1
                • SGaistS SGaist

                  Hi,

                  Can you share the code you use to save the image ?
                  How are you building the path ?

                  S Offline
                  S Offline
                  swagat
                  wrote on last edited by
                  #8

                  @SGaist It's a simple QString with a PNG as extention:
                  E.g: C:/Data/ARCHIVE/2021Jun04/Reports\TEST-Administrator-FAIL-20210602-194733.png

                  JonBJ 1 Reply Last reply
                  0
                  • S swagat

                    @SGaist It's a simple QString with a PNG as extention:
                    E.g: C:/Data/ARCHIVE/2021Jun04/Reports\TEST-Administrator-FAIL-20210602-194733.png

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @swagat
                    Verify that if you replace QImage::save(that_path) with, say, QFile::Open(that_path, QIODevice::WriteOnly); at the same point in code it saves.

                    C 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @swagat
                      Verify that if you replace QImage::save(that_path) with, say, QFile::Open(that_path, QIODevice::WriteOnly); at the same point in code it saves.

                      C Offline
                      C Offline
                      CleverFish
                      wrote on last edited by CleverFish
                      #10

                      @JonB
                      Yes, It does create file when replaced with suggested QFile::open() way. That indicates no permission issue.

                      JonBJ 1 Reply Last reply
                      0
                      • C CleverFish

                        @JonB
                        Yes, It does create file when replaced with suggested QFile::open() way. That indicates no permission issue.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #11

                        @CleverFish
                        Fair enough. So now what happens if you save the same image via QImage::save(path) with some safe path you are sure you can write to, C:\TEMP or whatever?

                        Then we should know whether it's the file path or the image conversion to save which is at issue.

                        You could also try saving it to same place but with a different extension, say .jpg, to see whether it could be a png thing.

                        C 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @CleverFish
                          Fair enough. So now what happens if you save the same image via QImage::save(path) with some safe path you are sure you can write to, C:\TEMP or whatever?

                          Then we should know whether it's the file path or the image conversion to save which is at issue.

                          You could also try saving it to same place but with a different extension, say .jpg, to see whether it could be a png thing.

                          C Offline
                          C Offline
                          CleverFish
                          wrote on last edited by CleverFish
                          #12

                          @JonB thanks for the response. I did try with.jpg and bmp file format but save() failed returns false.

                          JonBJ artwawA 2 Replies Last reply
                          0
                          • C CleverFish

                            @JonB thanks for the response. I did try with.jpg and bmp file format but save() failed returns false.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #13

                            @CleverFish
                            Then the save path seems to have nothing to do with it, does it? And it didn't save as other image formats. So presumably either that image is rubbish, or you cannot save any images at all?

                            C 1 Reply Last reply
                            0
                            • C CleverFish

                              @JonB thanks for the response. I did try with.jpg and bmp file format but save() failed returns false.

                              artwawA Offline
                              artwawA Offline
                              artwaw
                              wrote on last edited by
                              #14

                              @CleverFish might be dumb to ask but what if you try to save this using QFile? Same parameters for saving.

                              For more information please re-read.

                              Kind Regards,
                              Artur

                              C 1 Reply Last reply
                              0
                              • artwawA artwaw

                                @CleverFish might be dumb to ask but what if you try to save this using QFile? Same parameters for saving.

                                C Offline
                                C Offline
                                CleverFish
                                wrote on last edited by
                                #15

                                @artwaw I tried that too. It's able to create such file.

                                1 Reply Last reply
                                0
                                • JonBJ JonB

                                  @CleverFish
                                  Then the save path seems to have nothing to do with it, does it? And it didn't save as other image formats. So presumably either that image is rubbish, or you cannot save any images at all?

                                  C Offline
                                  C Offline
                                  CleverFish
                                  wrote on last edited by
                                  #16

                                  @JonB There is a new observation. If the application is lunched using the credentials through which it got installed, it's able to generate the reports without any issues.

                                  JonBJ 1 Reply Last reply
                                  0
                                  • C CleverFish

                                    @JonB There is a new observation. If the application is lunched using the credentials through which it got installed, it's able to generate the reports without any issues.

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by JonB
                                    #17

                                    @CleverFish
                                    We are back to possibly permissions. However I also wonder whether the environment --- perhaps the library files for converting to png --- are right for the installer but not for other users. Who knows.

                                    Plus, I now notice you are using Qt 4, so goodness knows.

                                    I think you should split your convert + save into separate operations. Assuming it exists in Qt 4, bool QImage::save(QIODevice *device, const char *format = nullptr, int quality = -1) const should save to memory. There is an example on that page. First check whether that works. If it does, you can use the QFile you say works to save the buffer to file. See if that works, or report which of the two fails.

                                    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