[gtkmm] Gtk::Combo BUG?
- From: "Serge S. Fukanchik" <fuxx mail ru>
- To: gtkmm-list gnome org
- Subject: [gtkmm] Gtk::Combo BUG?
- Date: Thu, 02 Oct 2003 12:31:56 +0400
Hi,
i need to clear combo drop down list, but every Gtkmm solution
i tried so far, fails to do so.
It looks natural to use following construct:
combo.get_list()->children().clear ();
get, list of drop down children and clear it,
but this code segfaults in my simple test case (please see attached
source), and i ended with use of gtk_list_clear_items:
gtk_list_clear_items ( GTK_LIST ( combo.get_list ()->gobj() ), 0, -1 );
So, what is `correct' way of removing items from Combo Drop Down?
And why `clear' method in class HelperList is implemented as
erase ( begin, end ) instead of just call to gtk_list_clear_items?
--
fuxx
#include <gtkmm.h>
#include <gtk/gtklist.h>
class MyWindow: public Gtk::Window
{
public:
MyWindow ();
private:
void clear1_cb ();
void clear2_cb ();
Gtk::VBox vbox;
Gtk::Button clear1_button;
Gtk::Button clear2_button;
Gtk::Combo combo;
};
void MyWindow::clear1_cb ()
{
combo.get_list()->children().clear ();
}
void MyWindow::clear2_cb ()
{
gtk_list_clear_items ( GTK_LIST ( combo.get_list()->gobj() ), 0, -1 );
}
char *items[]={
"first",
"second",
"third",
"last",
0
};
MyWindow::MyWindow ()
: clear1_button ( "Clear and fail" ),
clear2_button ( "Clear and work" )
{
set_title ( "Combo test" );
add ( vbox );
vbox.pack_start ( combo, Gtk::PACK_EXPAND_WIDGET, 5 );
vbox.pack_start ( clear1_button, Gtk::PACK_SHRINK, 5 );
vbox.pack_start ( clear2_button, Gtk::PACK_SHRINK, 5 );
show_all ();
std::vector < Glib::ustring > strings;
for ( int i = 0; items [ i ]; i++ )
{
strings.push_back ( items [ i ] );
}
combo.set_popdown_strings ( strings );
clear1_button.signal_clicked ().connect ( SigC::slot ( *this, &MyWindow::clear1_cb ) );
clear2_button.signal_clicked ().connect ( SigC::slot ( *this, &MyWindow::clear2_cb ) );
}
int main ( int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
MyWindow window;
window.show ();
Gtk::Main::run(window);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]