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?
-
@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. -
@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 ? -
@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 ?
-
@CleverFish
Fair enough. So now what happens if you save the same image viaQImage::save(path)
with some safepath
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 apng
thing. -
@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? -
@CleverFish might be dumb to ask but what if you try to save this using QFile? Same parameters for saving.
-
@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
QFile
you say works to save the buffer to file. See if that works, or report which of the two fails.