Tuesday, March 9, 2010

NetBeans and Qt

I originally started this blog with the idea of building an Android application and recording my experience.  School, work and other activities have sent this in a totally different direction.  I still plan on recording my development experiences here, the actual topics, though, have changed.

On to the reason for this post.  I was recently asked if I would be interested in doing some work writing an interface to a financial trading system.  The gist of the project is this - write an application that polls the market data specified, runs an algorithm against it, and notifies the user if the algorithm meets a certain threshold.  The makers of the software have conveniently supplied an API to read their data streams.  In fact, they have supplied an API for C++, Java, and POSIX.  Being a native Java developer, you would think that I would immediately go for that solution to the problem.  The truth is, if I end up doing this, that will be my likely path.

When I got to thinking about the problem domain, however, I thought I should be prepared for a different build. First off, consider the basic description - get market data, perform analysis, give result.  This is clearly intended to give the user the proper information to make a decision about a trade, and then act on it.  Clearly, the faster the application works, the better.  Now consider an application running in the JVM.  Basic operations between Java and other languages, given the high quality JIT implementations these days, is minimal.  I wouldn't expect to see a significant performance hit using Java as opposed to C++.  The second consideration, though, is garbage collection.  If I implement the system poorly, there may be periodic delays due to garbage collection. Heck, if I implement it correctly there may be delays.  Now I have to consider whether I think this will actually be an issue, and the answer is, probably not.  I can take actions to minimize GC and optimize the return of the results.  This got me thinking, though.  It would be nice to be able to write this in C++.  So I decided to make sure that I could.

The Development Stack

After some brief research I decided to go with the Qt library on NetBeans.  You can learn more about Qt here.  Why Qt and NetBeans?  Well Qt is an LGPL, cross platform component library with a neat Visual editor.  NetBeans is a high-quality Open Source IDE, with a lot of support for C++.  I could have gone with Eclipse, which is my primary IDE, but NetBeans has always had a leg up on this type of development in my book.

The Setup

NetBeans even has a nice tutorial on how to configure and set up a Qt project.  Too bad it is no longer accurate (Nod to Steve, "Yes this is another case of an OS project documentation being out-of-date").  Here is what I found:

  • The tutorial instructs you to install mingw, qt and msys separately.  This is not needed if you are using 4.6.2.  In fact, this won't work.  
  • This post suggests that Qt changed the version of the compiler they use in the latest bundle, and that they include mingw with the distribution.  
So, here is my short list of steps you need to follow to get Qt working with NetBeans:
  1. Make sure you have the JDK and NetBeans installed
  2. Make sure you have NetBeans C/C++ plugin 
  3. Install msys1.0 (As easy as following the defaults in the installer)
  4. Get the Qt installer, Full version. Follow the defaults  (The NetBeans tutorial says to only download the Qt libraries)
See how easy that was?  Much easier than the NetBeans tutorial suggested.  To make sure you can compile a  Qt project, there is one configuration item left.  Make a MinGW_Qt Tool Collection. 
  1. Go toTools->Options, C/C++.
  2. Click Add...
  3. Select the Qt mingw installation as your base directory (mine is at: c:\Qt\2010.02.1\mingw\bin
  4. Select mingw as your tool collection family.  Your collection configuration should look like the screen shot below

Build and Run

You should now be able to build and run the sample from the NetBeans tutorial.  Remember to make sure that your Qt Tool collection is the collection used for the build.


  1. I've tried using Netbeans as Qt editor, but in the end I chose Qt Creator. It may not be as matured as Netbeans, but it's fully intergrated and has been adding new features non stop. Give it a try, it's definitely a different experience from Netbeans.

  2. Just stay tuned and you'll see Qt Creator growing up to the task.

  3. I also used Qt Creator it seems pretty complete and full featured. What is interesting is that it appears that NetBeans just launches Qt Creator when you click on a UI artifact. So it combines the two IDE's into a single experience.