Search code examples
c++gtkgtkmmgio

gtkmm application with Gio file monitors


I need to monitor multiple directories for changes. I'm using Gtk::Main, calling Gio::Init, and adding directory monitors exactly as the documentation suggests. However, the callback is never called, for any directory. Do I need another loop solely for the monitors, and if so, how would I use it in conjunction with Gtk::Main?


Solution

  • I had the same problem in Vala and here is the complete solution.

    As pointed out by Andrea Azzarone, you can use the Gtk::Main loop.

    However, pay attention to your Gio::FileMonitor reference. At the end of the function, it is destroyed so that the callback won't be called if you don't keep a reference to the Gio::FileMonitor object.

    I found this idea in this answer.