Introduction to PyQt: light-weight cross-platform Solution for Qt

While i was getting handy with Qt, came the problem of porting the application to the other platforms. For me, the main aim while jumping in Qt application development is to make the application run on embedded boards like mini2440, Raspi etc. and this time the board was Raspberry Pi.
There was some UI based project to be ported to Raspi, which required the cross-compiling of whole QT IDE for the Raspi, and i got something called qtonpi. Which, i felt, would require some tedious long hours, which i didn’t have.
Probably you will get this in my next blog on Qt.
But for now, there was another option called (drums beat…) PyQt. 😛

PyQt
PyQt

Easy and light weight PyQt. it worked as magic. Almost every linux distribution has python installed and all you need is a PyQt dev-kit, which basically binds the Qt APIs to the python. It is really a light-weight package which can be easily installed in almost all linux-distros in all architectures.
Lets get started:

Setting the work environment and installations: 

The dev-kit can be found in synaptic manager or at terminal by typing:-

$sudo apt-get install pyqt4-dev-tools

thats all 😛

Working with python scripts: 
1. Create a script file with .py extension
2. There are two options:
a. Either add #!/usr/bin/python to the first line of the file
Reason: originally, unix did not know any field by its extension, so we have the put this c-bank inside the file to let it know which script it is.

I. Add execution permission to the script by $ chmod +x abc.py
II. $./abc.py

b. Or simply write python before the file name like $python abc.py
Working with pyqt4:
a.Design your GUI form in QtCreator to save time and use pyuic4 to compile the .ui file to .py file
(basically python-ui-compiler generate the corresponding code for python from .ui file)

$pyuic4 -x abc.ui -o abc.py

$python abc.py

b.Simply start writing your python script from scratch.

Since Qt contains a lot of classes, These classes have been categorized in several modules to ease their access:

  1. QtCore-handles non-gui functionality like time, file, directory,threads etc.
  2. QtGui-handles gui components like windows, widgets,colours, fonts, toolbars etc.
  3. QtNetwork-consists of classes for network programming
  4. QtXml-handles the XML files. provides both SAX and DOM APIs.
  5. QtSvg-contains classes for displaying the contents of SVG(Scalable Vector Graphics is a language for describing two-dimensional graphics and graphical applications in XML.) files.
  6. QtOpenGL handles 3D and 2D graphics using the OpenGL library.
  7. QtSql module contains classes for working with databases.

These have to be imported as per the need. Goto next blog for rest of the story.

Advertisements

About Shantanu Sharma

Currently working as Software R&D member in Samsung R&D India.

Posted on October 23, 2013, in Qt: The Face Of Embedded and tagged , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s