0

I have a set of QImages which come to a function (after a fixed interval of 4 seconds) and the function's job is to update the QLabel to show the new image.

While doing this, I can see a very obvious delay in the image rendering.

I had also followed the suggestions on the link:

Efficient way of displaying a continuous stream of QImages

But, even with using ImageDisplay in the link above, I can see a delay in image rendering.

Can anyone please suggest the best way to do this?

Below is the code.. The images required for the code to run are located at:

https://www.dropbox.com/sh/jiqdfqoiimjs7ei/AAAXezUeeCFyZXjNNOTmWZVga?dl=0

#include <QDialog>
#include <QtGui>
#include <QtCore>
#include <QApplication>
#include <QWidget>
#include <QImage>

class imageDisplay : public QWidget
{
    public:
        imageDisplay(QWidget*);
        ~imageDisplay();
        void setImage(QImage* img);

    private:
        QImage* m_image;

protected:
        void paintEvent(QPaintEvent* evt);
};

imageDisplay::imageDisplay(QWidget* parent) : QWidget(parent)
{
    m_image = 0;
    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}

imageDisplay::~imageDisplay()
{
}

void imageDisplay::setImage(QImage* img)
{
    m_image = img;
    repaint();
}

void imageDisplay::paintEvent(QPaintEvent*)
{
    if(!m_image) return;
    QPainter painter(this);
    painter.drawImage(rect(), *m_image, m_image->rect());
}

////////////////////////////////////
//
int main(int arc, char ** argv)
{
    QApplication theApp(arc, argv, true);

    QDialog* dlg = new QDialog();

    imageDisplay* wgt = new imageDisplay(dlg);
    wgt->resize(600,400);
    dlg->show();

    for(int i = 0 ; i <= 19; ++i)
    {
        sleep(1);
        QString fileName = "aaa" + QString::number(i) + ".png";
        QImage* img = new QImage(fileName);
        wgt->setImage(img);
    }

    return theApp.exec();
}
Community
  • 1
  • 1
Nishant Sharma
  • 341
  • 2
  • 5
  • 17
  • 1
    How big are your images? What exatcly do you mean by "I can see deley in image rendering"? – Mailerdaimon Mar 21 '16 at 10:50
  • You should also show some code, at least the function you are talking about. You could also see what happens if you force immediate repaint by calling the QLabel's `repaint()` method, instead of waiting Qt to decide when to update it. Also, add some timestamp debug prints, or do some other kind of profiling, so you can determine where exactly the delay happens. – hyde Mar 21 '16 at 11:04
  • Hi, The image size is just 50K.. By delay I mean, I can see that the repainting happens from top to bottom.. It's a wave kind of a thing and it is quiet noticeable... Code is exactly same as mentioned in the link I posted. – Nishant Sharma Mar 21 '16 at 11:54
  • In the link you posted the answer says it's quite fast: 40 FPS. Do you have 40 FPS? If not, your code is **not** the same as in the link or the problem is elsewhere. Right? (That's why we need your code.) – Lukáš Bednařík Mar 21 '16 at 12:11
  • I have added the code above.... Please have a look and suggest. – Nishant Sharma Mar 21 '16 at 16:10

0 Answers0