Re: What is the minimum number of lines to update a gui window without user clicking a button



Adding these methods to the Example class show how you can use a local
helper function. The downside is you having an extra method lying
around and remembering to use the right one in the right context; in
C++11 you could get rid of gui_append_mainloop() by using a lambda.

Edit: This uses the approach Gavin just suggested. He's right in that
I probably should have used that approach in the first place.

// Extra methods for Example 5
    /* Append to the textbuffer in a thread UNsafe manner. Should only
     * be used on the Main Loop. */
    void gui_append_mainloop(const Glib::ustring& str) {
        Glib::ustring text =  tb->get_text();
        text += "\n" + str;
        tb->set_text(text);
    }

    /* Threadsafe access to gui_append_mainloop */
    void gui_append(const Glib::ustring& str) {
        callback_dispatcher.send(sigc::bind(sigc::mem_fun(this,
&Example::gui_append_mainloop), str));
    }
// Extra methods for Example 5


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