[PySide] QByteArray.fromRawData from bytearray/numpy

許友綸 tim37021 at gmail.com
Mon Oct 19 12:26:42 CEST 2020


Thank you! Icfwm has provided a workaround for me. Creating the buffer with
QByteArray and let numpy wrap around it.

The use case is....
I shift the buffer and push new data in python thread. Signal update() on
each update. I want to reduce unnecessary copies

len=incoming.shape[1]
self.buf[..., :len] = self.buf[..., len:]
self.buf[..., -len:]=incoming
self.update.emit()

Originally I..
@Property(QByteArray)
def array():
    return QByteArray(self.buf.tobytes())

This single return involves two copy operations. Tobytes and the ctor.
If using fromRawData, I should keep a reference to the result of
self.buf.tobytes, otherwise it will be garbage collected....still,
tobytes() copy array...

The use case might be weird. I am not that familiar to PySide2, I would
like to know if there exist a way to do zero copy of internal buffer...

Jason H <jhihn at gmx.com> 於 2020年10月17日 週六 上午3:11 寫道:

> Well I don't know your exact use case but you could use a stream and read
> the points as they come in (i.e. audio data), or you could write a page and
> produce a signal or invoke a callback when the write is complete (i.e.
> image data)
>
>
>
>
> > Sent: Friday, October 16, 2020 at 1:07 PM
> > From: "Tim Roberts" <timr at probo.com>
> > To: pyside at qt-project.org
> > Subject: Re: [PySide] QByteArray.fromRawData from bytearray/numpy
> >
> > 許友綸 wrote:
> > >
> > > hi, QByteArray consturctor can take both bytes and bytearray as its
> > > argument
> > > The docs says it makes its own copy. I want a python buffer(numpy)
> > > changing in real-time to be plotted/processed in QML.
> >
> > How would Qt know that the data had changed and the plot needed to be
> > regenerated?   Since you need to refresh the plot when the data changes,
> > it's no more trouble to pass in the replacement array.
> >
> > --
> > Tim Roberts, timr at probo.com
> > Providenza & Boekelheide, Inc.
> >
> >
> > _______________________________________________
> > PySide mailing list
> > PySide at qt-project.org
> > https://lists.qt-project.org/listinfo/pyside
> >
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> https://lists.qt-project.org/listinfo/pyside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20201019/8128dfcb/attachment.html>


More information about the PySide mailing list