TreeModelFilter在GTK / Perl的 - 大约set_visible_func问题

问题描述 投票:1回答:1

我试图筛选使用GTK2一个liststore :: TreeModelFilter。我似乎无法找到使用Perl和我收到的语法错误示例在线。有人可以帮我下面的语法?该$ unfiltered_store是liststore。

$filtered_store = Gtk2::TreeModeFilter->new($unfiltered_store);
$filtered_store->set_visible_func(get_end_products, $unfiltered_store);
$combobox = Gtk2::ComboBoxEntry->new($filtered_store,1);

然后下面的地方:

 sub get_end_products {
      my ($a, $b) = @_;

      warn(Dumper(\$a));
      warn(Dumper(\$b));
      return true;     # Return all rows for now
 }

最后我想要做的就是看listore(unfiltered_store $)的14列,如果它是一个特定的值,然后将其过滤到$ filtered_store。

有人可以帮我在这句法?我查了一堆网站,但他们在其他语言,并使用不同的语法(如“new_filter” - 不使用Perl GTK存在)。这是最优雅的解决方案,以修复我需要和我宁愿学习如何使用这个,而不是使用拉和保存过滤数据的蛮力方法。

perl treeview gtk gtk2
1个回答
0
投票

过滤后储存的set_visible_func方法应该得到一个副参照作为第一个参数,但你是不是在这里传递一个子参考:

$filtered_store->set_visible_func(get_end_products, $unfiltered_store);

这将改为调用子程序get_end_products,然后传递它的返回值(这不是一个副参照)。要修复它在子名称前加上参考操作\&

$filtered_store->set_visible_func(\&get_end_products, $unfiltered_store);

至于在评论你的另一个问题:According to the documentation用户数据参数被作为第三个参数来传递get_end_products,所以你应该把它定义是这样的:

sub get_end_products {
      my ($model, $iter, $user_data) = @_;
      # Do something with $user_data
      return TRUE;
 }

如果由于某种原因$unfiltered_store不会传递到get_end_products,你可以尝试使用匿名sub代替,这样传递:

$filtered_store->set_visible_func(
    sub { get_end_products( $unfiltered_store) });
© www.soinside.com 2019 - 2024. All rights reserved.