File: d_sigslot.t

package info (click to toggle)
qt4-perl 4.5~~svn1145508-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,144 kB
  • ctags: 5,947
  • sloc: perl: 29,224; cpp: 18,849; xml: 98; makefile: 91; sh: 4
file content (58 lines) | stat: -rw-r--r-- 1,312 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package MyApp;

use Test::More tests => 4;

use QtCore4;
use QtGui4;
use QtCore4::isa qw(Qt::Application);
use QtCore4::slots
        foo => [],
        slotToSignal => ['int','int'],
        slot => ['int','int'];
use QtCore4::signals
        signal => ['int','int'],
        signalFromSlot => ['int','int'];

sub NEW {
    shift->SUPER::NEW(@_);

    # 1) testing correct subclassing of Qt::Application and this pointer
    is( ref(this), ' MyApp', 'Correct subclassing' );

    this->connect(this, SIGNAL 'signal(int,int)', SLOT 'slotToSignal(int,int)');
    this->connect(this, SIGNAL 'signalFromSlot(int,int)', SLOT 'slot(int,int)');

    # 4) automatic quitting will test Qt4 sig to custom slot 
    this->connect(this, SIGNAL 'aboutToQuit()', SLOT 'foo()');

    # 2) Emit a signal to a slot that will emit another signal
    emit signal( 5, 4 );
}

sub foo {
    ok( 1, 'Qt4 signal to custom slot' );
}     

sub slotToSignal {
    is_deeply( \@_, [ 5, 4 ], 'Custom signal to custom slot' );
    # 3) Emit a signal to a slot from within a signal
    emit signalFromSlot( @_ );
}

sub slot {
    is_deeply( \@_, [ 5, 4 ], 'Signal to slot to signal to slot' );
}

1;

package main;

use QtCore4;
use QtGui4;
use MyApp;

$a = MyApp(\@ARGV);

Qt::Timer::singleShot( 300, $a, SLOT "quit()" );

exit $a->exec;