Qt::Slider revisited

Wolfgang Hommel <[email protected]>
Newsgroups gmane.comp.kde.devel.perl
Message-ID <[email protected]>
Greetings!

Although it's been briefly discussed on the list just two weeks ago, I'd 
really appreciate some details on the "Qt::Slider isn't displayed" 
issue. I'm referring to the code of PerlQT tutorial 6, presently 
available at

http://perlqt.sourceforge.net/index.php?page=viewcode&file=tutorials/t6/t6.pl

Specifically this part:

package LCDRange;
use Qt;
use Qt::isa qw(Qt::VBox);

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

    my $lcd = Qt::LCDNumber(2, this, "lcd");
    my $slider = Qt::Slider(&Horizontal, this, "slider");
    $slider->setRange(0, 99);
    $slider->setValue(0);
    $lcd->connect($slider, SIGNAL('valueChanged(int)'), SLOT('display(int)'));
}


Now, when I run the tutorial code on PerlQt 3.008, Qt 3.3.1, Linux,

- the Slider doesn't show up at all, but the LCD does, as it should
- if I use a Qt::Pushbutton instead of a Qt::Slider, both the LCD and 
the Pushbutton show up for each LCDRange instance
- running the original tutorial code (with the Slider), but as .cpp 
source, works fine as well (slider shows up)

Now, if the above package is changed to:

package LCDRange;
use Qt;
use Qt::isa qw(Qt::VBox);

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

    my $lcd = Qt::LCDNumber(2, this, "lcd");
    $slider = Qt::Slider(&Horizontal, this, "slider");
    $slider->setRange(0, 99);
    $slider->setValue(0);
    $lcd->connect($slider, SIGNAL('valueChanged(int)'), SLOT('display(int)'));
}

(This has been suggested 2 weeks ago)

Then the Slider gets displayed, but (of course?) only the very last 
instance of all "LCDRange"s has got a Slider, the others don't; i.e., 
the example code creates 16 of them, but only the 16th (bottom right) 
got a Slider attached to it.

I can get it to work by actually using

package LCDRange;
use Qt;
use Qt::isa qw(Qt::VBox);

my $i = 0;
my @slider;
sub NEW {
    shift->SUPER::NEW(@_);

    my $lcd = Qt::LCDNumber(2, this, "lcd");
    $slider[$i] = Qt::Slider(&Horizontal, this, "slider");
    $slider[$i]->setRange(0, 99);
    $slider[$i]->setValue(0);
    $lcd->connect($slider[$i], SIGNAL('valueChanged(int)'), 
SLOT('display(int)'));
    $i++;
}

But I doubt that's elegant. :-)

Could someone please tell me,

- whether this is intentional behavior?
- why this only happens with Qt::Slider (does it?)?
- how the tutorial code should be modified more elegantly to make it 
work properly?

Thanks in advance,

Regards,
Wolfgang
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.