Qt: QGraphicsScene is not updated when I expect it to

So, I have QGraphicsScenein a class called eye. I call the function:

void eye::playSequence(int sequenceNum) {

    for (int i=0; i<sequences[sequenceNum].numberOfSlides(); i++) {
        presentSlide(sequenceNum, i);
        time_t start;
            time(&start);
            bool cont=false;
            while (!cont) {
                time_t now;
                time(&now);
                double dif;
                dif=difftime(now, start);
                if (dif>5.0)
                    cont=true;
            }
    }
}

which for each slide call:

void eye::presentSlide(int sequenceNum, int slideNum) {

    Slide * slide=sequences[sequenceNum].getSlide(slideNum);

    QGraphicsPixmapItem * pic0=scene.addPixmap(slide->getStimulus(0)->getImage());
    pic0->setPos(0,0);

    QGraphicsPixmapItem * pic1=scene.addPixmap(slide->getStimulus(1)->getImage());
    pic1->setPos(horizontalResolution-350,0);

    QGraphicsPixmapItem * pic2=scene.addPixmap(slide->getStimulus(2)->getImage());
    pic2->setPos(horizontalResolution-350,verticalResolution-450);

    QGraphicsPixmapItem * pic3=scene.addPixmap(slide->getStimulus(3)->getImage());
    pic3->setPos(0,verticalResolution-450);
}

Now I expect this to display one set of images, wait 5 seconds, then display the next, etc. Instead, it does not display anything until all slides have been processed and then the last four images are displayed. I tried calling scene.update()anywhere where the image could have been, and did nothing. It seems that the scene is updated only when the function returns playSequence. Any ideas what could happen here?

+3
source share
2 answers

, , , . , eye:: playSequence , , - ? , .

Qt . :

while(app_running)
{
  if(EventPending)
    ProcessNextEvent();
}

, , , . - , . .

- . - while QTimer 5 . . , ..

, qapp- > processEvents() presentSlide (sequenceNum, i). ( ) , .

, eye:: presentSlide() , , . , (). AddXXX :)

+7

, . - QApplication:: processEvents() while.

while - , . , .

QTimer , - 5 () , presentSlide(). playSequence().

+7

Source: https://habr.com/ru/post/1705891/


All Articles