Can't set values in ListStore/TreeView



I have been working on a  modest application using Perl-Gtk2 and have stumbled 
on a problem with populating lists.  I can set up a TreeView quite happily, 
and a model (ListStore for simplicity) to plug into it.  I can append lines to 
the ListStore and they show up nicely in the TreeView.  What I haven't been 
able to do, despite following what documentation I've turned up with Google, 
is to populate the list so that it shows up on screen.  I must be doing 
something wrong, or leaving something out, but what?

Stripped-down sample code, which exhibits this behaviour, is below.  Can 
anybody help?

------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl

use warnings;
use strict;

use Glib qw [TRUE FALSE];
use Gtk2 '-init';

my $mw = Gtk2::Window->new;
$mw->signal_connect(destroy => sub{Gtk2->main_quit});

my $liststore = Gtk2::ListStore->new('Glib::String');
my $treeview = Gtk2::TreeView->new($liststore);

my $render = Gtk2::CellRendererText->new;
my $col = Gtk2::TreeViewColumn->new_with_attributes("Name", $render);
$treeview->append_column($col);

$mw->add($treeview);

my @list = qw [Hugh Pugh Barney McGrew Cuthbert Dibble Grubb];
foreach (@list) {
        my $iter = $liststore->append;
        $liststore->set($iter, 0, $_);
}

$mw->show_all;
Gtk2->main;
------------------------------------------------------------------------------------------------------------------------


Thanks

Rosie




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