1
我想要一個簡單的Perl GtK GUI只包含一個窗口和一個垂直框。 我得到一個分段錯誤而在這之前的警告:「不能創建的抽象(非實例化的),例如輸入'GtkBox'」Perl Gtk無法創建抽象(非實例化)類型`GtkBox'的實例
的GUI是:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Text to EPUB</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>
的代碼是:
#!/usr/bin/perl
use warnings;
use strict;
use File::Spec::Functions qw(rel2abs);
use File::Basename;
use File::Copy;
use Glib;
use Gtk2 '-init';
my $basedir = dirname(rel2abs($0));
my $guifile = "$basedir/txt2epub1.gui";
print "GUI file: $guifile\n";
my $builder = Gtk2::Builder->new();
$builder->add_from_file($guifile) or die "Couldn't read $guifile";
$builder->connect_signals(undef);
my $window = $builder->get_object("window1") or die "Can't open main window";
$window->show_all();
Gtk2->main();
# Callbacks
sub cb_window1_destroy {
Gtk2->main_quit();
exit;
}