June 29, 2011

avidamic avidamic
Lab Rat
13 posts

poll method for QMainWindow

 

Is there already a method in QMainWindow that will get called every frame? I want to implement a polling method but I’m having trouble finding something like an “OnIdle” for this class.

7 replies

June 29, 2011

cincirin cincirin
Ant Farmer
467 posts

You can use QCoreApplication::hasPendingEvents [doc.qt.nokia.com] to check if the application is idle.

June 29, 2011

dialingo dialingo
Lab Rat
158 posts

I am not sure if I understood your requirement correctly but:

QTimer with setInterval(0) emits a signal as soon as the event queue is empty.

June 29, 2011

avidamic avidamic
Lab Rat
13 posts

I think the QTimer with 0 interval is what I need to do. Basically I need to have a method in my QMainWindow subclass to get called every frame. thanks.

June 29, 2011

Gerolf Gerolf
Robot Herder
3287 posts
avidamic wrote:
I think the QTimer with 0 interval is what I need to do. Basically I need to have a method in my QMainWindow subclass to get called every frame. thanks.

What do you mean by frame? This timer only calls you, when there is nothing else to do.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

June 29, 2011

avidamic avidamic
Lab Rat
13 posts

By every frame, I mean every tick, every time the application loops, etc. I’m a game developer and come from a MFC background so sorry if my terminology doesn’t make sense right off the bat.

June 29, 2011

Gerolf Gerolf
Robot Herder
3287 posts

MFC also does not talk of frames. The event loop (also in MFC) is just a while loop that waits for messages in a queue. In MFC there is afaik no method that is called each time, the loop is executed (not by default).

Every tick would be really fast as tick is typically processor dependent… And if you want to have it each loop, that is overwriting QCoreApplication::notify or installing an event Filkter on the application object. But that would only be called, if there is an event to process.

like in standard windows:

  1. while(GetMessage(msg))
  2. {
  3.     TranslateMessage(msg);
  4.     DispatchMessage(msg);
  5. }

You would hang in line 3, so if there is no methode —> no call.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

June 29, 2011

avidamic avidamic
Lab Rat
13 posts

Yep, it’s tough to come out of game lingo. Sorry for the confusion.

QTimer method worked for me though. Thanks!

 
  ‹‹ Visual Inheritance      qq-26-openglcanvas issues ››

You must log in to post a reply. Not a member yet? Register here!