Updating / displaying game objects using Qt

I would like to know how to update and display game objects when using Qt. For instance. with a typical game you will have an event loop, but Qt just has exec() . What is the correct way to update and render game objects using Qt? How do I do things like get time between each frame to update my game objects? Am I using a separate thread for all this?

My question is very similar to this thread , except that I am not trying to avoid the standard Qt processes.

Edit: Sorry for the incomplete question. I believe tmpearce already answered my question, but here is a basic example of what I'm trying to do if someone else has the same problem:

 int main(int argv, char **args) { QApplication app(argv, args); ApplicationWindow window; window.show(); // How and where do I update my Game object? return app.exec(); } class Game { public: void timeUpdate() { // Update game entities, etc. Should be called every frame. } void render() { // Renders game entities - where should I render to? // Should be called 30 times a second, etc. } }; 

Greetings.

+4
source share
1 answer

Qt has an event loop; It is launched by QApplication::exec() . I have no idea what your requirements are for updating and rendering; but since you seem to need an event loop like in a โ€œtypical gameโ€, I assume you can take it from there.

In your application, create a QTimer . Connect the timeout signal to the slot that you want to trigger in each event loop. Call QTimer::start(0) : each time it will call a timeout signal through an event loop.

Regarding time, check out QElapsedTimer - I suspect this is what you are looking for.

+7
source

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


All Articles