Re: Updating widgets in a thread in a new Gtk::Window



When I read your post, I get the impression that you already know what's wrong with your program. Or at least have a strong suspicion.

You update TestWindow::m_entry in the worker thread. That's not safe. Most of gtk+ and gtkmm are not thread-safe. You shall call widget functions only in the main thread.

Have you seen the example program in the gtkmm tutorial?
https://developer.gnome.org/gtkmm-tutorial/stable/sec-multithread-example.html.en

Kjell

Den 2015-03-03 07:12, someone_else Safe-mail net skrev:
Hello, I was reading the gtkmm tutorial and it says "Use Glib::Dispatcher to invoke gtkmm functions from worker threads." I have two Gtk::Windows, main window and a view window.

What I would like to do is have a thread that will update some widgets (Entrys, lables, and a Glib::RefPtr<Gdk::Pixbuf>) in the second window, because after the work is done the results will be displayed in that new window. So what I did was I show the new window and then thread the worker function in the new window. The worker function updates the widgets,
Don't do that.
 which I think is not thread safe
Correct
 because after calling the thread x amount of times, the program will crash.

 
 //Is this OK to do in a thread? Even for a Glib::RefPtr<Gdk::Pixbuf>?
 m_entry.set_text("blah");

No, do it in the main thread (the GUI thread).


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]