can3p → Serenity

Thu, 17 Aug 2023 00:28

One more interesting bit from the video, here is more or less the snippet:

Core::EventLoop event_loop;

auto qt_event_loop_driver = Core::Timer::create_repeating(50, [&] {
    app->process_events()
})

qt_event_loop_driver->start();

return event_loop->exec()

There are multiple questions one may ask:

The answer to the second question is simple - there should be a global object somewhere and it's indeed there in form of EventLoopManager class that's implemented as a singleton per system.

So the whole sequence goes as the following:

Timer -> EventReceiver -> EventLoopManager

when an event loop is run it actually calls exec on EventLoopManager so even though it looks like you can have many event loops you actually cannot.

And EventLoopManager does the actual things described in the docs

Getting back to the first question: it was done most probably because the initial implementation had only one process and that was the easiest way to make resource loading work - make qt take a back seat and invoke it only to draw the window every now and then

Dabdab.org (c) 2022 — 2023, hi@dabdab.org / Contact us / Twitter