Topic
2 replies Latest Post - ‏2009-05-06T16:56:57Z by SystemAdmin
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

Pinned topic Perl/Tk vs. PerlQt

‏2003-01-09T12:35:40Z |
Cameron's article about Perl/Tk is nice... it's a fine interface, but I can't help feeling the Tk toolkit is aging.

Have you heard about PerlQt ? http://perlqt.sourceforge.net (or package "Qt" on CPAN)

Due to current Qt licensing scheme, it is available only on POSIX systems (GPL license), but if portability to Windows isn't an issue, the advantages are simply overwhelming...

It can use Qt Designer, a complete and free RAD IDE bundled with Qt - so writing a GUI program is a breeze...
Reproducing Cameron's Kill_inetd example took 5 minutes, and I did it entirely from the IDE, drag and dropping, and writing the few lines of killThem()

The end result is identical to Cameron's, though more polished, but :
1- Since Qt uses utf-8, it handles i18n by default
2- It is entirely Object oriented, and nicely organised in a package, so you can reuse or even subclass the "kill" widget you just created at will
3- The syntax is incomparably more elegant and clean
4- widgets are beautiful, modern, and themeable
5- Signals and Slots are incredibly more powerful than callbacks
6- the .ui file created by the Designer is reusable immediately in C++, in case I was just prototyping

Here is the output of puic (the PerlQt User Interface Compiler) applied to the .ui file the Qt Designer created:

code
  1. Form implementation generated from reading ui file 'form1.ui'
#
  1. Created: jeu jan 9 10:21:45 2003
  2. by: The PerlQt User Interface Compiler (puic)
#
  1. WARNING! All changes made in this file will be lost!
use strict;
use utf8;
package Form1;
use Qt;
use Qt::isa qw(Qt::MainWindow);
use Qt::slots
killThem => [];
use Qt::attributes qw(
buttonGroup1
radioKill
radioTerm
textLabel1
lineEdit1
pushButton1
);

sub NEW
{
shift->SUPER::NEW(@_http://0..2);
statusBar();

if( name() eq "unnamed" )
{
setName("Form1");
}
resize(242,196);
setCaption(trUtf8("Form1"));

setCentralWidget(Qt::Widget(this, "qt_central_widget"));
my $Form1Layout = Qt::GridLayout(centralWidget(), 1, 1, 11, 6, '$Form1Layout');

my $layout2 = Qt::HBoxLayout(undef, 11, 6, '$layout2');
my $spacer = Qt::SpacerItem(57, 21, &Qt::SizePolicy::Expanding, &Qt::SizePolicy::Minimum);
$layout2->addItem($spacer);

buttonGroup1 = Qt::ButtonGroup(centralWidget(), "buttonGroup1");
buttonGroup1->setTitle(trUtf8("Choose a signal"));
buttonGroup1->setExclusive(0);
buttonGroup1->setColumnLayout( 0, &Vertical );
buttonGroup1->layout()->setSpacing(6);
buttonGroup1->layout()->setMargin(11);
my $buttonGroup1Layout = Qt::GridLayout(buttonGroup1->layout() );
$buttonGroup1Layout->setAlignment( &AlignTop );

radioKill = Qt::RadioButton(buttonGroup1, "radioKill");
radioKill->setText(trUtf8("KILL"));
radioKill->setChecked(1);

$buttonGroup1Layout->addWidget(radioKill, 0, 0);

radioTerm = Qt::RadioButton(buttonGroup1, "radioTerm");
radioTerm->setText(trUtf8("TERM"));

$buttonGroup1Layout->addWidget(radioTerm, 0, 1);
$layout2->addWidget(buttonGroup1);
my $spacer_2 = Qt::SpacerItem(57, 21, &Qt::SizePolicy::Expanding, &Qt::SizePolicy::Minimum);
$layout2->addItem($spacer_2);

$Form1Layout->addLayout($layout2, 2, 0);

textLabel1 = Qt::Label(centralWidget(), "textLabel1");
textLabel1->setText(trUtf8("<p align=\"center\">Control panel for killing processes<br>\n" .
"enter keyword here</p>"));

$Form1Layout->addWidget(textLabel1, 0, 0);

lineEdit1 = Qt::LineEdit(centralWidget(), "lineEdit1");

$Form1Layout->addWidget(lineEdit1, 1, 0);

pushButton1 = Qt::PushButton(centralWidget(), "pushButton1");
pushButton1->setText(trUtf8("Send signal to named processes"));

$Form1Layout->addWidget(pushButton1, 3, 0);

Qt::Object::connect(pushButton1, SIGNAL "clicked()", this, SLOT "killThem()");

init();
}
sub killThem
{

my $t = new Proc::ProcessTable;
my $k = lineEdit1->text;
do {
statusBar()->message("Please enter a keyword...");
return } unless $k;
my $sig = radioKill->isOn ? "KILL":"TERM";
foreach my $p (@{$t->table}) {
kill $sig, $p->pid if $p->cmndline =~ $k;
}
this->statusBar()->message("Signal $sig sent to all '$k' processes.");

}

sub init
{

require Proc::ProcessTable;

}

1;
package main;

use Qt;
use Form1;

my $a = Qt::Application(\@ARGV);
my $w = Form1;
$a->setMainWidget($w);
$w->show;
exit $a->exec;

[/code]

Here is a screenshot of the designing process :
http://www.phoenix-library.org/germain/shots/kill_design.png

And the actual results:
http://www.phoenix-library.org/germain/shots/kill_perlqt.png
Updated on 2009-05-06T16:56:57Z at 2009-05-06T16:56:57Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: Perl/Tk vs. PerlQt

    ‏2003-01-29T19:38:55Z  in response to SystemAdmin
    > Cameron's article about Perl/Tk is nice... it's a
    > fine interface, but I can't help feeling the Tk
    > toolkit is aging.
    >
    > Have you heard about PerlQt ?
    > http://perlqt.sourceforge.net (or package "Qt" on
    > CPAN)
    >
    > Due to current Qt licensing scheme, it is available
    > only on POSIX systems (GPL license), but if
    > portability to Windows isn't an issue, the advantages
    > are simply overwhelming...
    >
    > It can use Qt Designer, a complete and free RAD IDE
    > bundled with Qt - so writing a GUI program is a
    > breeze...
    > Reproducing Cameron's Kill_inetd example took 5
    > minutes, and I did it entirely from the IDE, drag and
    > dropping, and writing the few lines of killThem()
    >
    > The end result is identical to Cameron's, though more
    > polished, but :
    > 1- Since Qt uses utf-8, it handles i18n by default
    > 2- It is entirely Object oriented, and nicely
    > organised in a package, so you can reuse or even
    > subclass the "kill" widget you just created at will
    > 3- The syntax is incomparably more elegant and clean
    > 4- widgets are beautiful, modern, and themeable
    > 5- Signals and Slots are incredibly more powerful
    > than callbacks
    > 6- the .ui file created by the Designer is reusable
    > immediately in C++, in case I was just prototyping
    . . .

    ggarand: what a delightful posting! Many thanks for putting this up.

    First, I quite agree with you that PerlQt deserves attention. I last worked with it over a year ago now, and it was considerably less polished. Qt's a great toolkit, though, and I have high hopes for PerlQt. In fact, I think there's even reason to regard a Windows PerlQt as realistic; if others have an interest in this, please do write or follow-up here.

    I like your six enumerated advantages of PerlQt. You're right on target with these.

    PerlQt will surprise those coming from Perl/Tk in a few ways. Perl/Tk is great at exposing all its widgets' configuration variables. While one generally doesn't have to mess with them, they are available for special effects. The PerlQt philosophy is a bit different; visual effects are mostly achieved through themes. Also, there are small specific advantages to Perl/Tk--buttons can have both images and labels. Finally, Perl/Tk's geometry managers, and Canvas and Text widgets are quite popular. As cool as slots-and-signals are, Perl/Tk's tags are equally powerful.

    Again, thanks for all the detail on PerlQt you posted.
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: Perl/Tk vs. PerlQt

    ‏2009-05-06T16:56:57Z  in response to SystemAdmin
    I just want to let everyone know PerlQt is great and this site has a lot of tutorials on how to use it and lots of examples to download.

    http://perlqt.wikidot.com/

    PerlQt is a very fast and easy way to create great looking GUI programs using the Qt drag and drop form designer and Perl. PerlQt is powerful enough for advanced developers and easy for beginners as well.