QBuffer does not fill QByteArray problem
So, I try to fill QByteArray with data (and then save it to database). I use QFileDialog to obtain picture, QPixmap to paint it in a grid, and it works fine, but QByteArray, that is intende开发者_StackOverflow中文版d to be stored in db through sqlalchemy is empty after QPixmap::save(). Beside, signals, connected to bytesWritten and readyRead doesn't fire too. Pixmap is ok, grid contains a valid image after setData.
ba = QtCore.QByteArray()
buffer = QtCore.QBuffer(ba)
buffer.bytesWritten.connect(self.b)
buffer.readyRead.connect(self.c)
buffer.open(QtCore.QIODevice.WriteOnly)
pixmap.save(buffer)
buffer.close()
ba = buffer.data()
So, what am I doing wrong?
I think you need to specify the image file format when calling pixmap.save(), smth like this:
pixmap.save(buffer, 'PNG')
hope this helps, regards
精彩评论