In this article I’ll explain how to install QT Jambi and write your first Hello world program.
- Installation of QT Jambi SDK
- Quick Overview of the SDK
- Integration with Eclipse
- Your first Jambi Program
- Jambi Links
Installation of QT Jambi SDK
First, you need to download the “Qt Jambi – Java bindings Binaries” for your OS (about 100MB), get it from� here. Since I am using Ubuntu, the following instructions will be for Linux. You can extract the archive where you want, but remember the path because we’ll need it later on – I’ll refer to ita s JAMBI_PATH (/usr/local/lib/qtjambi-linux32-lgpl-4.5.2_01 in this example).
tar -xzf qtjambi-linux32-lgpl-4.5.2_01.tar.gz
sudo mv qtjambi-linux32-lgpl-4.5.2_01 /usr/local/lib/
Next we need to create a script to get QT Designer to generate .jui files for Java (instead QT/C++ .ui files). Name it jambi-designer.sh and insert the following code:
cd JAMBI_PATH
export CLASSPATH=`pwd`/qtjambi-4.5.2_01.jar:`pwd`/qtjambi-examples-4.5.2_01.jar:`pwd`/qtjambi-linux32-gcc-4.5.2_01.jar
export JAVADIR=/usr/lib/jvm/java-6-sun/jre
./designer.sh
Make it executable and make it available in your path. Copy also the juic (jambi user interface compiler) which is used to convert the files generated by the Designer to java code.
sudo chmod a+x jambi-designer.sh
sudo ln -s /JAMBI_PATH/jambi-designer.sh /usr/local/bin/jambi-designer
cp bin/juic /usr/local/bin/
# try it :
jambi-designer &
Quick Overview of the SDK
So here you go you got the SDK installed. Now what are these files, do i need to install this huge file on every computer my program will run unto?? Obviously not!
Well here, you to remember that when you’ll distribute your application, you’ll need to bundle it with the Jambi core package (qtjambi-4.5.2_01.jar) and the jambi os-dependant package (qtjambi-linux32-gcc-4.5.2_01.jar). That’s it!
If you want the application to run on Windows as well, you only need to add one jar file per os (you’ll need to download the whole sdk just to get the .jar your need for each os).
What else am I getting?
Directory / file | Details |
---|---|
bin | Designer and UI Compiler binaries |
com/trolltech/ | Jambi Core & Examples Source code |
doc/ | Jambi HTML Documentation (use your browser) |
qtjambi.sh | Execute this script to view the numeros code samples |
Integration with Eclipse
So you want code auto-completion for Jambi classes in Eclipse? You’re dreaming! Nope, actually you can! Just download the “eclipse integration package” and extract it in the plugin directory of your Eclipse installation.
Note : I haven’t been able to install the integration plugin with default Eclipse package in Kubuntu 9.10 because it does not allow you to add plugins as root. So to get around this, just uninstall it from the package manager and install it manually (get eclipse here).
tar -xzf eclipse-java-galileo-SR1-linux-gtk.tar.gz
sudo mv eclipse /opt/eclipse-3.5.1
cd /opt/eclipse-3.5.1
sudo tar -xzf /path/to/qtjambi-eclipse-integration-linux32-4.5.2_01.tar.gz
./eclipse -clean
Next on Eclipse restart, go to Window > Preferences > QT Jambi Preference Page and use these settings :
- Jambi Location = where you installed the first archive (JAMBI_PATH)
- Generate files in separate folder = src/ui
Your first Jambi Program
- Click on File > New > Other > QT Jambi Project.
Add a new class named “HelloWorld” and insert this code:
import com.trolltech.qt.gui.*; public class HelloWorld extends QWidget{ public static void main(String[] args) { // Instanciates a Jambi Application and pass it the command-line arguments to allow the QApplication // static instance to handle the arguments it recognizes, such as -font and -style. QApplication.initialize(args); // Creates an instance of our QWidget (could be also a QMainWindow, QDialog, etc.) // and set the parent to null HelloWorld helloWorld = new HelloWorld(null); // Create a new label and sets its parent to our view. QLabel label = new QLabel("Ping World!", helloWorld); // Show our view helloWorld.show(); // Execute Jambi Application QApplication.exec(); } public HelloWorld(QWidget parent){ super(parent); } }
Jambi Links
- Jambi Documentation (“Signals and Slots” is a recommanded reading)
- Jambi Classes javadoc
- file:///usr/local/lib/qtjambi-linux32-lgpl-4.5.2_01/doc/html/index.html (same as above but on your computer)
- C++ QT Documentation (the API is the same and sometimes you find more information than on Jambi)
- Getting Started Article by Jasmin Blanchette (including a part on how to integrate C++ components with QT Jambi)
- Jambi Examples