RE: [gtkmm] How do you determine iterator 'type' for get_children.begin() ?



The first two buttons in your code are the same buttons

button[0] = (Gtk::Button *) *(buttonbox->get_children().begin());
button[1] = (Gtk::Button *) *(buttonbox->get_children().begin()++);

you must try the following to obtain the first two buttons

button[0] = (Gtk::Button *) *(buttonbox->get_children().begin());
button[1] = (Gtk::Button *) *(++buttonbox->get_children().begin());

In your loop, the iterator has no <= operator, you must use the != operator.
This is,

int index = 0;
Gtk::Box_Helpers::BoxList::iterator i = buttonbox->get_children().begin();

while (i!= buttonbox->end())
{
	button[index++]=*(i++);
}

The other way , to iterate childs, is to use the ForEachSlot.

// ==================
class A { void f(Widget& widget); };
A obj;

// call
buttonbox->foreach(SigC::slot(obj, &A::f));
// ==================

PS: I don't test the above code. But it must be work :)


-----Original Message-----
From: gtkmm-list-admin gnome org [mailto:gtkmm-list-admin gnome org]On
Behalf Of Jeff Gavin
Sent: Mittwoch, 11. Juni 2003 19:08
To: gtkmm-list gnome org
Subject: [gtkmm] How do you determine iterator 'type' for
get_children.begin() ?


I'm trying to loop through each button in a button box and collect the
pointers to each of the button widgets.  So far I can do the following
because I know that there are 8 buttons in the button box.

button[0] = (Gtk::Button *) *(buttonbox->get_children().begin());
button[1] = (Gtk::Button *) *(buttonbox->get_children().begin()++);
button[7] = (Gtk::Button *) *(buttonbox->get_children().end());

The above code compiles and does what I want, it gives me the first,
second, and last button in my button box.

I cannot figure out what type 'i' should be in this example:

<WHAT TYPE GOES HERE?> i;
for (i = buttonbox->get_children().begin();
      i <= buttonbox->get_children().end();
      i++)
{
   button[j] = *(i);
}

How do you determine the type of the iterator.  I have tried to find an
example but cannot.  I have read and re-read the online documentation
for ListHandle and am very lost.

I even compiled the program with the type of 'int' and the compiler
complained:

cannot convert
`Glib::Container_Helpers::ListHandleIterator<Glib::Container_Helpers::TypeTr
aits<Gtk::Widget*>
 >' to `int' in assignment

I was hoping that the error message would give me a hint, but I'm still
not able to figure out the correct type to use for the iterator.I know
that an experienced C++ programmer would then know exactly what type to
use, but alas, I'm still new to C++.

Thanks for your help.

Jeff

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




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