JohnDoe
JohnDoe

Reputation: 23

QMovie unexpected argument QBuffer

Hi i thought QMovie could take QBuffer? This is my code.

a = QByteArray(img)
b = QBuffer(a)
self.movie = QMovie(b, 'GIF')

Upvotes: 1

Views: 185

Answers (1)

eyllanesc
eyllanesc

Reputation: 243945

You want to use the second constructor:

QMovie::QMovie(QIODevice *device, const QByteArray &format = QByteArray(), QObject *parent = nullptr)

and as you see it is expected that the second argument is a QByteArray that can be replaced by bytes, so in the next part I show you an example:

import sys
from PyQt5 import QtCore, QtGui, QtWidgets


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)

    # load data from
    path = "congratulations.gif"
    file = QtCore.QFile(path)
    if not file.open(QtCore.QIODevice.ReadOnly):
        sys.exit(-1)
    ba = file.readAll()


    buf = QtCore.QBuffer(ba)
    if not buf.open(QtCore.QIODevice.ReadOnly):
        sys.exit(-1)

    movie = QtGui.QMovie(buf, b"gif")
    w = QtWidgets.QLabel()
    w.setMovie(movie)
    movie.start()
    w.show()
    sys.exit(app.exec_())

Upvotes: 2

Related Questions