2009-12-16

Qt from F#

Qt, available at qt.nokia.com, is another popular toolkit that can be used to build cross-platform user interfaces.  Since Qt 4.5, released in 2009-03, it is available in the more commercial friendly LPGL. Previously, the open source edition was under GPL.  The best solution for using Qt from .NET right now is to use the Java binding.  Qt Jambi is the name of the project/product for the Java bindings.  Qt Jambi 4.5 is commercially supported, but 4.6 is not, only community supported.  Like Qt, Qt Jambi is now also LGPL and looks to be alive and well, looking at the git repository activity.

qt4dotnet provides Qt binding for .NET by applying some minimal patches to Qt Jambi and then builds it with IKVM (project, blog), which translates the Java bytecode to .NET CIL.  IKVM libraries are shipped with Mono.  The latest stable version 0.40.0.1 came out in 2009-06 and it ships with Mono 2.4.3 as well as 2.6.0 released yesterday.

If you have Visual Studio 2010 Beta 2 and a Subversion client like TortoiseSVN, you should be able to checkout this solution, open it, and run it by hitting F5.  If you install Mono, you can also run it using Mono by dropping into the Command Prompt, cd’ing to the bin\Debug directory and running “mono QtHelloWorld.exe”.  I tested it with Mono 2.4.3 and 2.6.0 on Windows 7 (64-bit, but should work on 32-bit too), as well as Mono 2.4.3 and 2.6.0 on Mac OS X 10.5, and Mono 2.4.2.3 and 2.6.0 on openSUSE Linux 11.1 VMware image.

svn checkout http://ctaggart.googlecode.com/svn/tags/blog-2009/2009-12-16/QtHelloWorld/

If you get the QtHelloWorld working and want to explore Qt some more, I would recommend the qt4dotnet wiki examples.  The Qt Jambi Reference Documentation is available online with the Qt Jambi API to help you out.

Figuring out the right combination of libraries to use took a while.  It was trial and error and I got help from the qt4dotnet discussion group (thanks guys!).  I’ve committed everything needed to run the example on Windows.  The .NET libraries are from the qt4dotnet’s qtjambi-4.5.2-all.zip.  The IKVM native libraries are from the Mono 2.6 installations on each OS.  The native Qt and Qt Jambi libraries I used were from http://get.qt.nokia.com/qtjambi/source/

It is possible to build cross-platform user interfaces using Qt and F#.  Enjoy exploring Qt.  BTW, the QtHelloWorld.fs can be seen here.