Difference between revisions of "Development/Languages/Perl"

Jump to: navigation, search
m (Text replace - "</code>" to "</syntaxhighlight>")
 
(4 intermediate revisions by 2 users not shown)
Line 13: Line 13:
 
== Non-SMOKE bindings  ==
 
== Non-SMOKE bindings  ==
  
You can read more about [http://qt-apps.org/content/show.php/Perl+Qt4?content=69748 Perl bindings for Qt 4] and [http://klv.lg.ua/~vadim/perlqt4/ download Perl Qt4].  
+
You can read more about [http://qt-apps.org/content/show.php/Perl+Qt4?content=69748 Perl bindings for Qt 4] and [http://code.google.com/p/perlqt4/ download Perl Qt4].
  
 
= Hello PerlQt4  =
 
= Hello PerlQt4  =
  
<code perl="perl">
+
<syntaxhighlight lang="perl">
  
 
#!/usr/bin/perl
 
#!/usr/bin/perl
Line 30: Line 30:
 
$hello->show();
 
$hello->show();
 
exit $app->exec();
 
exit $app->exec();
</code>  
+
</syntaxhighlight>  
  
 
= API Overview  =
 
= API Overview  =
Line 44: Line 44:
 
*QtCore  
 
*QtCore  
 
*QtGui  
 
*QtGui  
 +
*QtDBus
 +
*QtNetwork
 
*QtTest
 
*QtTest
 +
*QtXml
  
 
=== KDE  ===
 
=== KDE  ===
Line 63: Line 66:
 
== Properties  ==
 
== Properties  ==
  
Some classes in Qt are implemented using publicly accessible properties, like the QStyleOption classes. To set properties, call a method called "set&lt;PropertyName&gt;", like <code perl="perl">
+
Some classes in Qt are implemented using publicly accessible properties, like the QStyleOption classes. To set properties, call a method called "set&lt;PropertyName&gt;", like <syntaxhighlight lang="perl">
 
$styleOption->setDirection();
 
$styleOption->setDirection();
</code>  
+
</syntaxhighlight>  
  
 
== Operator overloading  ==
 
== Operator overloading  ==
  
The full range of Qt operator methods is available, for example: <code perl="perl">
+
The full range of Qt operator methods is available, for example: <syntaxhighlight lang="perl">
 
my $p1 = Qt::Point(5,5)  # (5, 5)
 
my $p1 = Qt::Point(5,5)  # (5, 5)
 
my $p2 = Qt::Point(20,20) # (20, 20)
 
my $p2 = Qt::Point(20,20) # (20, 20)
 
$p1 + $p2                # (25, 25)
 
$p1 + $p2                # (25, 25)
</code>
+
</syntaxhighlight>
  
 
== Subclassing ==
 
== Subclassing ==
Line 79: Line 82:
 
To define a subclass, declare a package, and then use the "QtCore4::isa" module.  Pass the name of the class you're subclassing as an argument, similar to the syntax for "use base".
 
To define a subclass, declare a package, and then use the "QtCore4::isa" module.  Pass the name of the class you're subclassing as an argument, similar to the syntax for "use base".
  
<code perl>
+
<syntaxhighlight lang="perl">
 
package MyWidget;
 
package MyWidget;
 
use QtCore4;
 
use QtCore4;
 
use QtCore4::isa qw( Qt::Widget );
 
use QtCore4::isa qw( Qt::Widget );
</code>
+
</syntaxhighlight>
  
 
== Signals and Slots ==
 
== Signals and Slots ==

Latest revision as of 21:49, 29 June 2011

Perl is a powerful and versatile high-level programming language. You can find out more about the language itself on the Perl website.

Contents

[edit] Qt 3

Complete object-oriented bindings for Qt 3, based on SMOKE, are available on the PerlQt project page. Those bindings provide virtual functions overloading, custom slots and signals, and Rapid Application Development (RAD) through puic, a Qt Designer compatible user interface compiler.

[edit] Qt 4

[edit] SMOKE based bindings

The Qt 3 bindings have been ported to work with Qt 4, and is included with the kdebindings module for KDE SC 4.5. The rest of this document supplies information about these bindings.

[edit] Non-SMOKE bindings

You can read more about Perl bindings for Qt 4 and download Perl Qt4.

[edit] Hello PerlQt4

#!/usr/bin/perl
 
use strict;
use warnings;
use QtCore4;
use QtGui4;
 
my $app = Qt::Application( \@ARGV );
my $hello = Qt::Label( 'Hello, World!' );
$hello->show();
exit $app->exec();

[edit] API Overview

The PerlQt4 API mimics PerlQt3 very closely. So if you have written using PerlQt3, the transition should be very easy.

[edit] Coverage

PerlQt4 is modular, where one Perl module will load one Qt/KDE module. Modules currently exist for:

[edit] Qt

  • QtCore
  • QtGui
  • QtDBus
  • QtNetwork
  • QtTest
  • QtXml

[edit] KDE

  • KDECore
  • KDEUi
  • KIO
  • Plasma

[edit] Available methods

All Qt public and protected methods are supported, as well as friend methods.

[edit] Virtual Methods

All virtual methods can be overridden by Perl subroutines.

[edit] Properties

Some classes in Qt are implemented using publicly accessible properties, like the QStyleOption classes. To set properties, call a method called "set<PropertyName>", like
$styleOption->setDirection();

[edit] Operator overloading

The full range of Qt operator methods is available, for example:
my $p1 = Qt::Point(5,5)   # (5, 5)
my $p2 = Qt::Point(20,20) # (20, 20)
$p1 + $p2                 # (25, 25)

[edit] Subclassing

To define a subclass, declare a package, and then use the "QtCore4::isa" module. Pass the name of the class you're subclassing as an argument, similar to the syntax for "use base".

package MyWidget;
use QtCore4;
use QtCore4::isa qw( Qt::Widget );

[edit] Signals and Slots

Signals and slots are declared by use'ing the QtCore4::signals and QtCore4::slots modules. The arguments is an array of string/arrayref pairs, where the items in the array define the types of arguments that signal/slot accepts. In the background, it is building a C++ method signature.


This page was last modified on 29 June 2011, at 21:49. This page has been accessed 15,271 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal