Saturday, June 13, 2009

Java Basics Using Qt Jambi Tutorial

QT Jambi

Now that we have discussed the basics of the Java Language, we move on to using Qt Framework in our Java Programs.

We are going to use an example project that would explain on how Qt works.

The program will be a photo slideshow with these requirements:

  1. Import photos and show it.

  2. Import music.

  3. Play the slideshow.


Using Qt Designer

Qt designer is an interface that helps you design your application. Just like GUI designing in other IDE such as Visual Studio or Eclipse, Netbeans, etc.

When designing the GUI (Graphical User Interface), you can use the Qt Jambi Designer included in the Qt Jambi SDK or the Eclipse Qt Integration plugin. Since we are learning the fundamentals, it is better to use the Qt Designer that comes with Qt Jambi SDK, then convert the GUI you designed to Java code.


Since we already made our first application using the steps in “The Basics,” “Using Qt Designer,” we'll just tell you what to add in our photo slideshow.


  1. List Widget

  2. Text Label

  3. Horizontal Slider

  4. (3) Push buttons

  5. Menu with these:

File->Import Photos->Import Music->Exit


It is recommended to rename these “widgets” using the Object Inspector Located on the right side of the designer by clicking the tab below. This will aid you on your coding for it is easier to remember because it will show up in your produced Java code and avoid variable name clashes by making it unique.


I won't write the source code here since it is not efficient, instead go to this http://javaqt.blogspot.com/2008/11/java-using-qt-jambi-tutorial-example.html and copy it.


The program works as it should, but it has “bugs” (errors) in it as to teach you Java using Qt Framework. Read the comments the ones after the “//” or “/*” and “*/”.

In the program or code, there are lines of code which I used String Builder, but a fixed array should be used instead.

In debugging (fixing) the code, I would suggest that you print out the variables or objects to see if the values it contain is correct (although, you can also see the values of variables on some decent IDEs like Eclipse, etc.) like,

System.out.println(variable); throughout the program.

In Java development, I always encounter problems on using class variables, like in a GUI in Qt, therefore add the keyword “static” so it would have one copy of that variable to use (this is also called static fields).

It is recommended that you read APIs (Application Programming Interface) documentation (and I know you would) and study it on how to use it. Search on the Internet for these or go to: http://java.sun.com/docs/books/tutorial/index.html download it, and the documentation included on the Qt Jambi SDK.

When creating a program, always think on solving one problem at a time, it is good practice that you design your program first on paper, but of course in reality, this isn't so.

Always make sure that you test your programs thoroughly before giving it to your boss because results matter.

So, I leave you with an unfinished program so you could experiment on. Happy Programming!


No comments: