Friday, April 29, 2011

gtkmm: update gui from other thread?

I am using gtkmm (and glibmm), and I would like to update the GUI from another thread. I have followed the example on

http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/thread_2dispatcher_8cc-example.html#_a1

but I have 2 questions:

  • Instead of a Glib::MainLoop receiving the events, is it possible for a Gtk::Main (that runs my window) to accept signals?

  • Can I .connect() functions with arguments in some way? I know it is possible using SigCX but I thought the syntax there was a bit nasty.

THanks!

From stackoverflow
  • You could have your Glib::MainLoop receive the events, then dispatch it to Gtk::Main.

    I believe the only way to connect with custom arguments is to use sigc::bind.

    For example, say you wanted to pass in an integer, as well as a pointer to the widget in question:

    pWidget->signal_foo().connect( 
                sigc::bind<int, Gtk::SomeWidget*>( 
                    sigc::mem_fun( *this, &Bar::OnFooBar ), i, pWidget ) );
    

0 comments:

Post a Comment