PDA

View Full Version : Saving a QPixmap Object problem



StrikerX
13th November 2007, 10:57
Hi, i want to save a QPixmap object as File.png...

format=QtCore.QString("png") #to QString.
intitialPath=QtCore.QDir.currentPath()+"/snapshot"+str(self.counter)+"."+format

fileName=QtGui.QFileDialog.getSaveFileName(self, "Save As", intitialPath, "PNG Files (*.png);;All Files (*.*)" )
if not fileName.isEmpty():
self.originalPixamp.save(fileName, format.toAscii())
self.counter += 1
self.counter is just for formatting the snapshot name.

Error:

self.originalPixamp.save(fileName, QtCore.QString(format.toAscii()))
TypeError: argument 2 of QPixmap.save() has an invalid type

However, in C++ i used it the same way and it works ?!

I'm using PyQt4
Thanks in advance.

wysota
13th November 2007, 11:04
toAscii() returns a QByteArray. Use "PNG" or toAscii().constData() instead.

StrikerX
13th November 2007, 17:24
toAscii() returns a QByteArray. Use "PNG" or toAscii().constData() instead.
Thanks,

self.originalPixmap.save(fileName, format.toAscii().data())
works fine.

wysota
14th November 2007, 10:08
Why not self.originalPixmap.save(filename, "PNG")?

StrikerX
15th November 2007, 02:19
Actually any 'd have worked, but the problem was about Spelling !
Wrong variable_name:
self.originalPixamp
It should be: self.originalPixmap,

Thanks again.