Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GTK/Perl中的TreeModelFilter-关于集合可视函数的问题_Perl_Treeview_Gtk_Gtk2 - Fatal编程技术网

GTK/Perl中的TreeModelFilter-关于集合可视函数的问题

GTK/Perl中的TreeModelFilter-关于集合可视函数的问题,perl,treeview,gtk,gtk2,Perl,Treeview,Gtk,Gtk2,我正在尝试使用GTK2::TreeModelFilter筛选liststore。我似乎在网上找不到一个使用perl的示例,我发现语法错误。有人能帮我理解下面的语法吗?$unfiltered_存储是一个列表存储 $filtered_store = Gtk2::TreeModeFilter->new($unfiltered_store); $filtered_store->set_visible_func(get_end_products, $unfiltered_store); $co

我正在尝试使用GTK2::TreeModelFilter筛选liststore。我似乎在网上找不到一个使用perl的示例,我发现语法错误。有人能帮我理解下面的语法吗?$unfiltered_存储是一个列表存储

$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中不存在)。
这是我需要进行的修复的最优雅的解决方案,我更愿意学习如何使用它,而不是使用蛮力方法来提取和保存过滤数据。

过滤存储的
set\u visible\u func
方法应该获得一个子引用作为第一个参数,但您没有在此处传递子引用:

$filtered_store->set_visible_func(get_end_products, $unfiltered_store);
这将调用子程序
get_end_products
,然后传递其返回值(它不是子引用)。要修复此问题,请在子名称前面添加参考运算符
\&

$filtered_store->set_visible_func(\&get_end_products, $unfiltered_store);
关于评论中的其他问题: 用户数据参数作为第三个参数传递给
get\u end\u products
,因此您应该这样定义它:

sub get_end_products {
      my ($model, $iter, $user_data) = @_;
      # Do something with $user_data
      return TRUE;
 }
$filtered_store->set_visible_func(
    sub { get_end_products( $unfiltered_store) });
如果由于某种原因,
$unfiltered\u store
未传递到
获取最终产品
,您可以尝试使用匿名
子项
传递它,如下所示:

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

筛选存储区的
set\u visible\u func
方法应获得一个子引用作为第一个参数,但您没有在此处传递子引用:

$filtered_store->set_visible_func(get_end_products, $unfiltered_store);
这将调用子程序
get_end_products
,然后传递其返回值(它不是子引用)。要修复此问题,请在子名称前面添加参考运算符
\&

$filtered_store->set_visible_func(\&get_end_products, $unfiltered_store);
关于评论中的其他问题: 用户数据参数作为第三个参数传递给
get\u end\u products
,因此您应该这样定义它:

sub get_end_products {
      my ($model, $iter, $user_data) = @_;
      # Do something with $user_data
      return TRUE;
 }
$filtered_store->set_visible_func(
    sub { get_end_products( $unfiltered_store) });
如果由于某种原因,
$unfiltered\u store
未传递到
获取最终产品
,您可以尝试使用匿名
子项
传递它,如下所示:

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


您需要传递对
get\u end\u products
子例程的引用。所以试试
$filtered\u store->set\u visible\u func(\&get\u end\u products,$unfiltered\u store)
你的意思是这样的$过滤存储->设置可见功能(\&get\u end\u products,$unfiltered\u store);仅供参考,即使在通过引用传递之前,也会调用“get_end_products”函数。我的问题更多地与商店有关——如何在“获取终端产品”功能中访问商店?这两个转储程序语句不打印任何内容,但是在get_end_products函数中打印一个警告语句(如“Hello World”)确实有效。嘿!我刚刚添加了参考,而且…它很有效!程序不会崩溃。我真是太感谢你了。很高兴听到你这么说!请注意,通常,变量
$a
$b
排序
函数使用的特殊变量。因此,不建议使用这些变量名。您需要传递对
get\u end\u products
子例程的引用。所以试试
$filtered\u store->set\u visible\u func(\&get\u end\u products,$unfiltered\u store)
你的意思是这样的$过滤存储->设置可见功能(\&get\u end\u products,$unfiltered\u store);仅供参考,即使在通过引用传递之前,也会调用“get_end_products”函数。我的问题更多地与商店有关——如何在“获取终端产品”功能中访问商店?这两个转储程序语句不打印任何内容,但是在get_end_products函数中打印一个警告语句(如“Hello World”)确实有效。嘿!我刚刚添加了参考,而且…它很有效!程序不会崩溃。我真是太感谢你了。很高兴听到你这么说!请注意,通常,变量
$a
$b
排序
函数使用的特殊变量。所以不建议使用这些变量名。你太棒了。非常感谢。如果我使用匿名sub,我如何访问迭代?我只是将其作为第二个参数传递到匿名子系统中,等等?还是只是循环模型,等等?是的,您可以尝试像这样传递它
sub{get\u end\u products($\u[1],$unfiltered\u store)}
。现在第一个参数是迭代,因为
@
应该等于
($model,$iter,$user_data)
我无法检查模型迭代的值。执行$val=$model->get_value($iter,$data)将返回“找不到对象方法‘get_value’…”错误。在返回true/false之前,我需要查看列的值。我做错了什么?你太棒了。非常感谢。如果我使用匿名sub,我如何访问迭代?我只是将其作为第二个参数传递到匿名子系统中,等等?还是只是循环模型,等等?是的,您可以尝试像这样传递它
sub{get\u end\u products($\u[1],$unfiltered\u store)}
。现在第一个参数是迭代,因为
@
应该等于
($model,$iter,$user_data)
我无法检查模型迭代的值。执行$val=$model->get_value($iter,$data)将返回“找不到对象方法‘get_value’…”错误。在返回true/false之前,我需要查看列的值。我做错了什么?