PDA

View Full Version : How to display images continuously in qt by using QPixmap



swarupa
2nd February 2016, 18:03
hi all ,
I am new to Qt
can anybody help me for displaying images continuously in qt
my sample code is here

int i = 1;
for(; i < 31 ; i++)
{
char buffer[50] = "/home/rupa/Qtdisplay/";

sprintf(str2, "%i.jpeg", i);
strcat(buffer, str2);
QFile jpgfile(buffer);
jpgfile.open(QFile::ReadOnly);
QByteArray contents = jpgfile.readAll();
image.loadFromData(contents, "JPEG");
scene = new QGraphicsScene(this);
scene->addPixmap(image);
ui->graphicsView->setScene(scene);
ui->graphicsView->show();


}

anda_skoa
2nd February 2016, 19:42
Instead of a loop you need to process this in a way that allows Qt to process events inbetween images.

For example use a QTimer to regularily call a slot (see http://doc.qt.io/qt-5/signalsandslots.html) and in that slot you created the filename and load the image.

And you only need to create the scene once.
If you want to add images just add them like you do now, if you want to replace the image, keep the pointer to the QGraphicPixmapItem and just update its pixmap.

Cheers,
_