Sunday, March 16, 2008

Hello Qt Jambi in NetBeans

Qt is a multiplatform C++ GUI development framework. For java developers who like Qt and don't like Swing programs' look in Linux, Qt Jambi could be a good choice. It hasn't been developed as long as Qt but Trolltech's sites claim it provides all the functionality of Qt. The latest version was released on March 13 and version 4.4 is on the way.

There is a plugin for Eclipse IDE. It should provide access to the Qt Jambi documentation and Qt Designer from within the Eclipse. But what about NetBeans? I've just installed NetBeans 6.1 Beta which is much better than 6.0.1 I was using before. It would be fine to have full integration of Qt Jambi in NetBeans but it's still possible to use it for everything except designing GUI. You simply run Qt Designer, create UI and write code in NetBeans. You will probably also miss a resources manager (for adding pictures, sound files ... to your project). I don't know how to use Trolltech's documentation in NetBeans.

There are quite a lot of examples and tutorials on Trolltech's sites (as part of documentation). So let's try to write a 'Hello World!' program. Launch NetBeans and create a new project (Java -> Java Application) called e.g. HelloWorld.

Let's write method main:

Now we can see NetBeans does not know Qt's classes. Download Qt Jambi from here and extract it. Select Tools->Libraries from NetBeans' menu. Click 'New Library ...' and choose and type the name of library, e.g. QtJambi. Now click 'Add JAR/Folder ...', navigate to the directory where you extracted the library and choose file qtjambi.jar. Now click on Libraries in your project and choose Add Library. In following dialog choose QtJambi.



Now we can add imports in usual way.


Now we are prepared to run our first java program using Qt. In Linux (KDE) it will look like this:

1 comments:

Anonymous said...

You can create a library Tools->Libraries->New Library, called QtJambi.

Having put the Qt Jambi files in D:\QtJambi.

Then add the Qt jar file to the library classpath, i.e. D:\QtJambi\Qtjami-4.4.2_01.jar.

Then add the Qt javadoc files to the library, i.e. D:\QtJambi\doc\html.

Then add the new global library to your project.

We now have library imports, completion and javadocs!

On my system you have to add -Djava.library.path=D:\Qtjambi\bin to the VM options under Project Properties or else java cannot find the required dll files.

You could add D:\Qtjambi\bin to our PATH, but that rasther cluters up PATH.

joew60@yahoo.com