Re: Glib::Object::Subclass, embedding and multiple interpreters

On Mar 31, 2005, at 6:58 AM, Eduardo M KALINOWSKI wrote:

I'm doing something like this:

package KCWin;
eval {
 # if we're alive here, the package is already registered.
} or Glib::Type->register_object('Gtk2::Window',
                                signals => { activate => {} });

sub new {
 my $class = shift;

 my $self = bless Gtk2::Window->new, $class;

that's your problem. you're registering a new GType, but not using. re-blessing is not at all the same as creating a GType instance -- the reblessed Window is still a Window as far as glib is concerned. you want

sub new {
    return Glib::Object::new (__PACKAGE__);

which actually triggers the whole GObject instantiation process for your new subtype. the rest of your new impl would go into INIT_INSTANCE.

GLib-GObject-WARNING **: gsignal.c:1664: signal `activate' is invalid for instance `0x852cfd8' at <the line of $kcw->signal_connect>

Yes, because when you reblessed, you didn't actually affect the underlying GType. The new instance is not of your newly-registered subtype.

This worked with "use Glib::Object::Subclass etc", even tough what is now a new method was INIT_INSTANCE and the Gtk2::Window creating and blessing was not necessary.

Because Glib::Object::Subclass gives you the new() i listed above. Your code should not change from what you had with Glib::Object::Subclass --- you'll just have to provide a new() to replace the one that Subclass is no longer giving you.

Without treatment, a common cold will last about seven days.
With treatment, it will last about a week.
  -- conventional wisdom

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