Hello World! Qt Jambi
Let me clear first. I am a Python guy, most of my projects are written in Python programming language. I only had a few small projects written in Java before, I was never a Java guy. However, I do know the power of Java and now, I think it’s time to take advantage of Java, for powerful GUI toolkit.
People who want to develop GUI applications in Python always come into a question, “Which GUI toolkit should I use?” I tried Tk a few years ago, which comes with Python standard library, but definitely is not a good choice for large projects. Then I switched to wxPython, which is much better than Tk, but I was still unsatisfying with its GUI design tool. Finally, I met Qt.
Qt probably is the best GUI toolkit right there in my opinion. Though there are some Python bindings for Qt like PyQt and PySide, I found that both of them are not useful for me because PyQt is still only available under GPL and commercial licenses even though Qt is available under LGPL license since version 4.5, and PySide just seems not ready for Windows and Mac users.
Finally, I decided to use Qt Jambi, which is the Qt library made available for Java, and is officially supported by Nokia Corporation. My original thought was to use Qt Jambi with Jython, so I can take advantage of both Java and Python, and able to develop my applications under LGPL license.
The first step to a new programming language or library is always a simple “Hello World!” application, but I found that I was in trouble when I was following the official documentation, and that’s why I wrote this article. Here’s my working environment:
Before you start writing your “Hello World” application. You should make sure everything is working fine, this could be done by launching the Demo Launcher application included in Qt Jambi. Go open a Terminal window and change directory to the Qt Jambi installation directory. Then try to execute the `qtjambi.sh` script. If something is going wrong, simply open the `qtjambi.sh` file and find a line near the end of the file:
java -XstartOnFirstThread -cp $CP com.trolltech.launcher.Launcher
Then, add `-d32` after `java` like this:
java -d32 -XstartOnFirstThread -cp $CP com.trolltech.launcher.Launcher
Now execute the `qtjambi.sh` script again and everything should work fine now.
Next, we need to setup the environment for our Jambi applications. I made this by adding some lines to `.profile` file under my user’s home directory. You need to create one if you don’t have it yet. Once you have this file, add following lines to the button of the file:
# Qt Jambi
export QTDIR=/Users/olliwang/workspace/qtjambi-mac-lgpl-4.5.2_01
export DYLD_LIBRARY_PATH=$QTDIR/lib:$DYLD_LIBRARY_PATH
export QT_PLUGIN_PATH=$QTDIR/plugins
for lib in $(ls $QTDIR/qtjambi*.jar); do
CLASSPATH=$lib:$CLASSPATH
done
export CLASSPATHNote that only the `QTDIR` variable located in second line should be modified to point to your Qt Jambi installation directory. After you done, we can start make our “Hello World” application now.
Before you write your “Hello World” application, you need to choose a directory to place your Java source code, not the Qt Jambi installation directory, please. I created a new directory and switched directory to it in my Terminal window. Now you can create a file called “HelloWorld.java” and write the following code (borrowed from the Qt Jambi official documentation):
import com.trolltech.qt.gui.*;
public class HelloWorld
{
public static void main(String[] args)
{
QApplication.initialize(args);
QPushButton hello = new QPushButton("Hello World!");
hello.resize(120, 40);
hello.setWindowTitle("Hello World");
hello.show();
QApplication.exec();
}
}
After saving that file, back to your Terminal window, and compile the source code by running
javac HelloWorld.java
Finally, you can execute the application by running
java -d32 -XstartOnFirstThread HelloWorld
And the result should look like this:

Done!
Filed under: Java, Mac, Programming, Qt | 4 Comments
Tags: GUI, Hello World, Java, Mac, Programming, PyQt, PySide, Python, Qt, Qt Jambi, Snow Leopard, Tk, toolkit, tutorial, wxPython




Hi Olli Wang,
nice post !
pls continue submit qt jambi
just curious, when you build desktop application(business application) what report generator you’ve used with QT ?
In Java as well know is JasperReport with visually using iReport which could embedded into my swing desktop application, the report shown simply by produce jasper.reportView().
thanx
rgrds,
rk
Hi, rk,
Unfortunately I’m not a experienced Java programmer and I’m new to Qt Jambi too, so my answer may not be what you want.
In the Python world, there’s a well-known Sphinx document generator, and there’s a matplotlib plotting library. You may also take a look at SphinxReport, which “glues” matplotlib with Sphonx. By using Sphinx, you can write your document or report by reStructuredText once, and produces various formats such as HTML, LaTex, and PDF. Then, you can embed them in your Qt applications.
hi olli please tell me how to work with qtjambi… i want to work with netbeans… my OS is windows… waiting for ur reply.. thanks in advance…
Sorry, I’ve not used WIndows in a long time. Maybe this would help: http://doc.trolltech.com/qtjambi-4.5.0_01/com/trolltech/qt/qtjambi-installation.html