Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 173181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:17:52+00:00 2026-05-11T13:17:52+00:00

Ok so I’ve got a QGraphicsScene in a class called eye. I call a

  • 0

Ok so I’ve got a QGraphicsScene in a class called eye. I call a 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 calls:

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 would expect this to display one set of images, wait for 5 seconds, then display the next, and so on. Instead, it displays nothing until all the slides have been processed and then the last four images are displayed. I’ve tried calling scene.update() in every place I could image and it didn’t do anything. It seems like the scene only updates when the playSequence function returns. Any ideas what might be going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:17:53+00:00Added an answer on May 11, 2026 at 1:17 pm

    This is the kind of behaviour that is often seen in event driven GUI frameworks when one wants to do continuous animation. I’m going to guess that eye::playSequence is called from a button click or maybe from some point during the application startup code? In any case, here is what’s going on.

    Qt uses the main application thread to drive an event loop. The event loop is something like this:

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

    The problem you are seeing is that updates to the screen are done during a paint event. If you are running some code during a mouse click event or any other event, then all the drawing you are doing is queued up and will be drawn to the screen on the next paint event. Sometimes it takes awhile for this to sink in.

    The best way to address this is to change your approach a bit. One way is to throw away your while loop and setup a QTimer set to fire every 5 seconds. In the timer slot you can draw one slide. When the timer fires again, draw the next slide, etc.

    If you want a more direct and less elegant quick fix, try calling qapp->processEvents() right after your call to presentSlide(sequenceNum, i). This (most of the time) will force the application to clear out any queued up events which should include paint events.

    I should also mention that eye::presentSlide() is merely adding new scene objects to the scene on each iteration covering the ones that were added during the last call. Think of the scene as a fridge door and when you call scene().addXXX you are throwing more fridge magnets on the door 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 241k
  • Answers 241k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In your first example, menu will be deleted when this… May 13, 2026 at 7:23 am
  • Editorial Team
    Editorial Team added an answer Look at this from php.net $to = 'nobody@example.com'; $subject =… May 13, 2026 at 7:23 am
  • Editorial Team
    Editorial Team added an answer Bugzilla, Mantis or Trac all work just fine with Mylyn.… May 13, 2026 at 7:23 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
Ok so I thought it was fixed, but I'm getting totally inconsistent results. I
Ok so I've ordered Applying Domain-Driven Design and Patterns: Using .Net , but while
OK so I'm looking a some code which looks roughly like this: void DoSomething(object
Ok so I have an abstract base class called Product, a KitItem class that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.