PDA

View Full Version : qImage saving to jpg problem



sqarpi
1st September 2010, 12:41
Hello again.
I have problems with saving qImage to jpg.
On the very begining i was trying to use QPixmap::save() like this:


QString saveFile=QFileDialog::getSaveFileName(this,tr("save"),QDir::homePath());
if(!saveFile.isEmpty())
if(!tlo->save(saveFile,".JPG",100));

but it didn't work(no errors, just was not saving file), so i have tried qimagewriter and... on the one computer it's working on the other not... the code is:


QString saveFile=QFileDialog::getSaveFileName(this,tr("save"),QDir::homePath());
if(!saveFile.isEmpty()){
QImageWriter writer(saveFile);
writer.write(*tlo);
if(writer.canWrite())
qDebug("i can write");
else
qDebug("i can't write");
qDebug()<< writer.errorString();
}


it shows me "i can write" co there is no problems with opening file to write and no problems with qimage... the error line is "unknown problem"
any ideas about the solution? any ideas why save() didn't work? i really will appreciate help.
thank

Lykurg
1st September 2010, 12:57
Make sure you have the jpeg plugin on the right place that your app can find it.

wysota
1st September 2010, 12:58
The format name is "JPG" or "JPEG" and not ".JPG".

sqarpi
1st September 2010, 13:01
The format name is "JPG" or "JPEG" and not ".JPG".

Thanks, fixed, but save() still doesn't work. It gives me true as return, but dosn't save the file.

wysota
1st September 2010, 13:07
Check the path, maybe it saves the image in a different directory than you expect.

sqarpi
1st September 2010, 15:17
That would be the idea, but it takes path from QFileDialog. Anyway, can't find such file in any directory. Doesn't matter with save. Just why on one computer i have problems with QImageWriter, on the other not. Same Qt 4.6.0 from same instalation files, different OS - winxp(works) win764b(doesn't work).

wysota
1st September 2010, 15:22
That would be the idea, but it takes path from QFileDialog.
And that makes it impossible to dump it to the console?

sqarpi
1st September 2010, 15:26
qDebug(saveFile.toLatin1)
shows correct path.

wysota
1st September 2010, 15:29
So check if the location is writable to the current user, etc. Also dump QImageWriter::supportedImageFormats() to the console.

sqarpi
1st September 2010, 15:43
That's it. Opening program as an administrator helped, but funny, i didn't have such problems with writing a text to file.
Thanks mates for the brainstorm. :)