Search code examples
c++multithreadingsignalsgtkmm

Gtkmm : How to update UI from another thread? continuously


Thread A: a UI thread where the Gtkmm's message loop runs.

Thread B: receives data over network and logs it to a file.

Now I want that same data that's dumped into a file in thread B, also to be displayed in a Gtk::TextView on the UI at the same time. What's the nicest way to do that?

Glib::Dispatcher doesn't take data along. So it's only good for notifying about work-done's.

libSigCX just makes me sad.


Solution

  • I would try using Glib::Dispatcher along with a Glib::Threads::Mutex (or equivalent) protected std::queue<std::string> data structure. Use the dispatcher to notify the UI thread of each work item after you've put it on the queue.