I don't think that QPointer does what you think. You are constantly allocating new QGraphicScene
s. That's why you are running out of resources.
- The scene should be held by the window or outside.
- The
QGraphicsPixmapItem*
returned byaddPixmap
should be remebered. - The
setPixmap (const QPixmap &pixmap )
method ofQGraphicsPixmapItem
should be called to update the image.
For example:
class PixmapView
: public QGraphicsView
{
public:
QPlotView( QGraphicsScene *scene)
: QGraphicsView( scene )
, pixmap( 256, 256 )
{
pixmapItem = scene->addPixmap( pixmap );
buffer.resize( 256*256*4 );
startTimer( 100 );
}
void timerEvent( QTimerEvent* )
{
QImage image( &buffer[0], 256, 256, QImage::Format_ARGB32 );
pixmapItem->setPixmap( QPixmap::fromImage( image ) );
}
private:
std::vector<uchar> buffer;
QPixmap pixmap;
QGraphicsPixmapItem* pixmapItem;
};
Edit:
You are also constantly allocating new QTimer
s. A single timer should be a member of the window as it needs to survive the end of the method.