Re: Gtk2::TreeModel::foreach callback not getting any arguments?



On Sat, 2003-09-20 at 23:00, Dan Lyke wrote:

[Please don't start a new thread by replying to a message.]

First: I'm browsing a rather large tree which could have a lot of
images, so I want to be able to load and unload images as the tree
gets browsed. I'm doing a:

    $treestore->foreach($iterator, forEach, ['populate', $self->{-nodemapping}]);

on the expand message, but although my "forEach" callback is getting
called, it isn't getting any arguments. Any hints?

Hu. That's quite irritating. The above code should print a warning and
exit the whole program. Even more confusing is that you actually managed
to get your callback called.

Anyway, the signature of Gtk2::TreeModel::foreach is:

  void        gtk_tree_model_foreach          (GtkTreeModel *model,
                                               GtkTreeModelForeachFunc func,
                                               gpointer user_data);

which maps to:

  $treestore->foreach(callback, user_data);

Gtk2::api explains how to map from C to Perl.

As you see, there's no iterator argument. There used to be. In GTK+
1.2.x. You're probably using old documentation. The canonical reference
is:

  http://developer.gnome.org/doc/API/2.0/gtk/index.html

Furthermore, you shouldn't use barewords to pass in callbacks. Either
use anonymous sub routines:

  $treestore->foreach(sub { ... }, [...]);

or references to sub routines:

  $treestore->foreach(\&forEach, [...]);

The fact that you got away with the bareword implies that you're not
using warnings and strict. You should.

  use warnings;
  use strict;

HTH,
-Torsten




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