Re: Subclasses and signals with PerlQT

Yanick <[email protected]>
Newsgroups gmane.comp.kde.devel.perl
Message-ID <[email protected]>
On Thu, Jul 29, 2004 at 12:32:15PM +0200, [email protected] wrote:
> Is there a way to connect a signal in a class B which inherits from a
> class A, where this signal is implemented?
> I have tried, but the signal is never emitted!

I probably misundertand what you are trying to acheive, but it seems to
work pretty straightforwardly :

use Qt;

package Darth;
use Qt::isa qw/ Qt::Widget /;

sub NEW {
	shift->SUPER::NEW(@_[0..2]);
	this->connect( this, SIGNAL("useTheForce()"), SLOT( "feelTheForce()") );
}

sub useTheForce : SIGNAL();

sub feelTheForce : SLOT() {
	print this." feels a disturbance in the Force\n";
}

package Padawan;
use Qt::isa qw/ Darth /;

sub NEW {
	shift->SUPER::NEW(@_[0..2]);

	this->connect( this, SIGNAL( 'useTheForce()' ), SLOT('react()') );
}

sub react : SLOT() {
	print "It felt like a million toes wiggling\n";
}

package main;
use Qt;
use Darth;
use Padawan;
my $a = Qt::Application;

my $vader = Darth;
emit( $vader->useTheForce() );

my $luke = Padawan;
emit( $luke->useTheForce() );

exit $a->exec;


Joy,
`/anick
-- 
"The longer I live the more I see that I am never wrong about anything, and that
all the pains that I have so humbly taken to verify my notions have only wasted my
time." - George Bernard Shaw (1856-1950)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.