def _setReply(self, job, contentType, content): ''' @param: job QWebEngineUrlRequestJob @param: contentType QByteArray @param: content QByteArray ''' buf = QBuffer(job) buf.open(QIODevice.ReadWrite) buf.write(content) buf.seek(0) job.reply(contentType, buf)
def send_reply(rq, mime_type, data): if sip.isdeleted(rq): return # make the buf a child of rq so that it is automatically deleted when # rq is deleted buf = QBuffer(parent=rq) buf.open(QIODevice.OpenModeFlag.WriteOnly) # we have to copy data into buf as it will be garbage # collected by python buf.write(data) buf.seek(0) buf.close() rq.reply(mime_type.encode('ascii'), buf)
def processPendingDatagrams(self): while self.udpSocket.hasPendingDatagrams(): datagram, host, port = self.udpSocket.readDatagram( self.udpSocket.pendingDatagramSize()) buf = QBuffer() b = buf.write(self.udpSocket.readAll()) buf.seek(buf.pos() - b) image = QImage() image.loadFromData(buf.buffer()) image.save(r"D:\test.png")