Qimage::save() fails
-
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.
-
Is you location where you want to store your image writeable by the application?
-
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.
@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. -
Is you location where you want to store your image writeable by the application?
@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.
-
Hi,
Can you share the code you use to save the image ?
How are you building the path ? -
@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.@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); -
What does pthj contain ?
-
@SGaist It's a simple QString with a PNG as extention:
E.g: C:/Data/ARCHIVE/2021Jun04/Reports\TEST-Administrator-FAIL-20210602-194733.png -
@swagat
Verify that if you replaceQImage::save(that_path)with, say,QFile::Open(that_path, QIODevice::WriteOnly);at the same point in code it saves.@JonB
Yes, It does create file when replaced with suggested QFile::open() way. That indicates no permission issue. -
@JonB
Yes, It does create file when replaced with suggested QFile::open() way. That indicates no permission issue.@CleverFish
Fair enough. So now what happens if you save the same image viaQImage::save(path)with some safepathyou are sure you can write to,C:\TEMPor 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 apngthing. -
@CleverFish
Fair enough. So now what happens if you save the same image viaQImage::save(path)with some safepathyou are sure you can write to,C:\TEMPor 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 apngthing.@JonB thanks for the response. I did try with.jpg and bmp file format but save() failed returns false.
-
@JonB thanks for the response. I did try with.jpg and bmp file format but save() failed returns false.
@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? -
@JonB thanks for the response. I did try with.jpg and bmp file format but save() failed returns false.
@CleverFish might be dumb to ask but what if you try to save this using QFile? Same parameters for saving.
-
@CleverFish might be dumb to ask but what if you try to save this using QFile? Same parameters for saving.
@artwaw I tried that too. It's able to create such file.
-
@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?@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.
-
@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.
@CleverFish
We are back to possibly permissions. However I also wonder whether the environment --- perhaps the library files for converting topng--- 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
QFileyou say works to save the buffer to file. See if that works, or report which of the two fails.