Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How g_main_loop works in gtk programming?

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?

like image 592
cppdev Avatar asked Oct 15 '22 11:10

cppdev


1 Answers

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.

like image 106
unwind Avatar answered Oct 25 '22 08:10

unwind