I am new to GTK+ programming. I came across an API called g_main_loop()
. I have used it in my code but I am still unaware that how exactly it works. Can somebody explain g_main_loop()
with small code snippet?
I recommend reading the documentation, starting with the linked-to function g_main_loop_new()
.
Basically, letting glib "own" your application's main loop makes it easier to support things like "pluggable" event sources; where your application listens to both (for example) events coming from GTK+ widgets, and a network socket or Unix pipe. These are things that need to be hooked together at a fairly low level in an application's main loop, and letting glib own those parts makes it easier.
There are glib data structures (like IO channels) that are compatible with the main loop and allow you to add things to the set of inputs the loop manages. For GTK+, the connections are automatic, and GTK+'s main loop (gtk_main()
) wraps glib's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With