Wednesday, February 9, 2011

Windows + Netbeans + MinGW + Qt


NetBeans is an excellent IDE developed primarily for Java. For several years now it has also offered a C++ plugin which by using GNU compilers is able to turn it into a C++ IDE. In addition there is also the possibility of integrating Nokia's Qt development suite into NetBeans for GUI's and other visually rich apps. However getting these three components to work together under Windows is very tricky. I've done it several times now on several systems and each time I have to go and trawl through forums to get it all functioning together. So I decided to blog it all here mostly for my own use but also to try and bring all this info together in one place for others. I have followed this procedure successfully on Windows XP, Vista and 7

Download stuff:
First gather your materials. You will need to download:
Java Development Kit 6: Do this from the Oracle website You can download a version with Netbeans 6.9.1 bundled:

Next you need to get the Qt SDK from Nokia. I choose the LGPL version (that's the free one) but there's a commercial one depending on your license requirements. Here you should download
the complete QtSDK for windows - this includes a copy of MinGW 4.4 which has the C++ compilers - more about this later. It also includes Qt Designer which will enable you to do visual development of your Qt forms in Netbeans.

Finally you need MSYS version 1.0.11 (What's that? I'll tell you later). Get it here:
Do not be tempted to follow any of the instructions on that page! We're going to get MinGW from the Qt installation. Okay, so here is the installation order:

Installing Qt/MinGW

First, run the Qt installer. When given the option you should install MinGW as well as Qt and Qt Creator. When the install is finished uncheck run Qt Creator.

Now you should install MSYS. If you don't already know: Although NetBeans IDE has a C++ plugin, all it does is display C++ files prettily and help you navigate and write your code in an easy manner. It does not contain a compiler or linker to actually produce an executable from your code. When we installed Qt we also installed MinGW which is a "Minimal GNU for Windows". GNU is a set of open source compilers and development tools developed for UNIX/Linux systems. MinGW is a Windows port of them - however to work properly they need some UNIX stuff which comes from MSYS - which is a Minimal SYStem for windows - essentially a collection of ported UNIX tools and utilities. Most importantly it contains a version of "make" - the version which is in MinGW is (for some arcane reason I don't understand) incompatible with NetBeans. So - do the MSYS install. Once it has finished it will pop up with a command window telling you about a post-install. You need to do this!

Hit 'y' for yes you want to do the post install, the 'y' for do you have MinGW installed. Then you need to enter where it is installed - go to explorer and have a hunt around in the Qt directory. If you didn't change anything during the Qt installation you should have something like: C:\Qt\2010.05\mingw. You should enter that but using / slashes instead of \ . MSYS then does a bunch of stuff and makes some sarcastic comment about MinGW's version of make. MSYS installation is now complete.

Installing Netbeans / JDK

Now (finally!) you can install Netbeans / JDK. Run the installer you got from Oracle and then - once you answered the default questions go and have a coffee - it's going to be a while! Once it is done you should start NetBeans. The first time you start it, it will almost certainly tell you to update some part of itself via a little icon in the status bar. I usually go ahead and let it do that. This usually requires a restart of the program and usually causes it to want to update something else - again I let it do this until it stops asking me to update things!

Installing C/C++ plugin

As it is, the Netbeans you have installed is purely a Java development environment - we want to get C++ functionality so we need to install the C/C++ plugin. Go to Tools>>Plugins in Netbeans main menu and switch to the available plugins tab. Check the C/C++ plugin (along with any other plugins you fancy!).


Click the Install button. You may have to restart the IDE again.

Configuring C/C++ plugin

In order to get the C++ plugin working you need to tell it where the compilers are. To do this close down NetBeans. Add to your system PATH variable the directories for:
MSYS (c:\msys\1.0\bin)
MingGW (c:\Qt\2010.05\mingw\bin)
Qt (c:\Qt\2010.05\qt\bin)
You will have to check these paths are appropriate for your system. They should be the directories that contain, make.exe, g++.exe and qmake.exe respectively.

Now restart Netbeans and go to Tools>>Options and switch to the C++ tab. Netbeans should now automatically detect your GNU compilers and Qt. If it does not you may need to use "add..." to set up the tool set manually (setting the location of g++.exe as the base directory).

So we're there now yes? WRONG! You can now start a Qt/C++ project okay but there are a couple more steps. Go to the Code Assistance tab in the options Tools>>Options dialog again and within the C++ compiler tab (yes tabs in tabs in tabs!) add the include directory for the Qt core header files (in my case this C:\2010.05\qt\include).

Correcting your qmake specs

You should now be up and running. Probably restart the IDE again here. But then start a new Qt project (under new project dialog choose C/C++ project >> C/C++ Qt Application). If you just build the auto-generated code you should find everything is okay. Likewise if you add any non-Qt code. However there are a few problems. Try to create a new Qt form (choose to create a C++ wrapper class when you do this) in your project and you'll see what I mean - first of all it will open Qt Designer so you can visually design your form - now exit and you will find your C++ wrapper for the form is full of squiggly red lines. This is okay - you need to compile once for the Qt pre-processor to generate all it's magical behind the scenes stuff. But it still wont build - you'll get some weird message like this:
make[2]: c:/Qt/2010.05/qt/binuic.exe: Command not found
Sure enough if you check out your Qt directory you will find there is indeed no binuic.exe , like me you will probably spend some time searching for this exe to find it is nowhere on your disk, then start trawling the internet to see if you can download it from somewhere - it doesn't - there is no such thing. There is however a file called uic.exe in C:/Qt/2010.05/qt/bin the confusion comes about in your "qmake specs".
This is a file which tells qmake (the Qt pre-processor) how to build your Qt project. There is a / vs. \ slash confusion caused by Windows and other OS systems using different slashes as directory separators. Basically all you have to do is navigate to C:/Qt/2010.05/qt/mkspecs/win32-g++ (again the first part of this path - the 2010.05 may be different for you) . There you will find a file called qmake.conf edit it in notepad or whatever and find this section near the bottom:

QMAKE_MOC = $[QT_INSTALL_BINS]${DIR_SEPARATOR}moc.exe
QMAKE_UIC = $[QT_INSTALL_BINS]${DIR_SEPARATOR}uic.exe
QMAKE_IDC = $[QT_INSTALL_BINS]${DIR_SEPARATOR}idc.exe

I have found the easiest thing to do is to just rewrite these three lines as:

QMAKE_MOC = $$[QT_INSTALL_BINS]/moc.exe
QMAKE_UIC = $$[QT_INSTALL_BINS]/uic.exe
QMAKE_IDC = $$[QT_INSTALL_BINS]/idc.exe

And save qmake.conf (you may want to make copy of the old version first) DO NOT diddle with any other part of this file unless you know what you're doing!

Configuring yout Qt/C++ project

You're environment is now completely set up for Qt/C++ development in Netbeans. However, when you start a new project there are a couple of project settings you need to ensure you set.
Start a new Qt/C++ project and once it is created right-click on the project node and choose "properties".
You will get a property tree. First thing is to make sure under the "Build" branch you have the toolset selected that you set up under Configuring the C++ plugin. Next go to "Build/Qt". Right at the bottom under "Expert" you'll see Qmake spec. On that line enter "win32-g++" The qmake spec we just modified.
In the line immediately bellow (Custom Definitions) I advise you enter CONFIG+=console. This is optional but without it things like cout, printf and QDebug will not produce any output - not a problem if you are going 100% GUI but can be a pain while debugging.
If you do want console output you will also need to set Console type to "Output window" under the Run branch of the tree.

And that should do it! Let me know if any of this doesn't work. Next time I may write some tips on getting the QWT scientific plotting library to work under this set up too.

:)




Wednesday, August 6, 2008

Tree Cells

So my trusty assistant Nicole and I have been trying to separate cells from a wood core of a Red Oak so that we can put them though our new flow cytometer. So far this is our procedure -
  • We chop the core up into little bits.
  • We boil them in a mixture of hydrogen peroxide and glacial acetic acid under liebig condenser for three hours.
  • We cool the mixture and vacuum filter through an 8 micron filter rinsing a couple of times with saline to clear out all the acid.
  • We take the filter paper and use a needle to tease apart any remaining lumps.
  • Scrape the filtrand and rinse the paper into a small amount of saline solution with pectinase and EDTA.
  • Stir the suspension on a hot plate at about 40 degrees for 3 hours, subjecting it to ultrasound for 3 minutes at the beginning middle and end.
  • Draw the suspension into a syringe and force through a 400 micron polyethylene mesh.
The resulting filtrate is found to contain mostly free cells. These are rectangular and roughly 15 microns across with lengths ranging from about 50 to 100 microns. They have a clearly visible cell wall about 2 microns thick with what appear to be small 1 micron wide pores randomly distributed around them. Here are some microscope pictures we took of the samples.

Without the final mesh filter step we find that there are also an abundance of other larger structures. This includes long smooth fibres (which appear to be hollow) 15-20 microns wide and 1-2 mm long. There are also sheets and tubes of another material which seem to be covered in small pores.

Without the pectinase step we find many more of the rectangular cells stuck together in regular stacks.

Thursday, February 7, 2008

Whale




So this is my latest blender creation - yes a whale, for no reason in particular!

Monday, January 21, 2008

Too much time


So, one of my little projects at the moment is trying to learn how to use Blender (the open source 3D modeling/animation package). I've been using it this term for my lectures. This is my latest creation, for my quantum 2 lectures, the first few squared spherical harmonics. I wrote a python script to draw the curves. Of course I could have downloaded an image of these and so not stayed up until 1am writing my script and so have already had my actual lecture prepared ... but where's the fun in that!

Friday, October 12, 2007

RANT: Al Gore?!

Okay, Al Gore might be a nice enough guy and I'm sure he's worried about climate change in a nice middle-class baby-boomer kind of way - but the Nobel freaking Peace Prize?!! This man was vice-president of the most powerful (and polluting) nation in the world for - what was it 4 years? - and during that time he never showed the slightest serious interest in environmental issues and neither did his boss Bill "The American Way of Life is not up for Negotiation" Clinton.
The thing that really sticks in my craw though is this idea that somehow his little film has awoken the world to climate change! Everything in it has been said over and over again. Scientists and other such skruffy hippies have be talking about this for decades. As a kid in the 70's I read books about pollution and other environmental issues (including the greenhouse effect) and yet now suddenly people are saying "oh thanks for bringing this to our attention Al we had no idea".
So Al: I'm glad you've woken up and got the message at last and you've probably done some good drilling this into that intransigent section of the American public who still think it's their god-given right to munch through every last scrap of the planet like pigs at the trough. We certainly need people like you on-side, but credit where credit is due - there have been dozens of (better) documentaries over the years which have addressed these issues but were just dismissed as leftist ranting, the Nobel Peace Prize should not be given out just for having good timing and slick publicist.
RANT ENDS ....

Thursday, October 11, 2007

Campaign for The Noether


I've just delivered my lecture in momentum to my intro physics class and it occurred to me - why is there no derived unit of momentum? So I'm putting in my two-penniesworth that we should call it the noether (With 1 noether = 1 kg m / s) after Amalie Emmy Noether the German-born mathematician and mathematical physicist. There are several reasons for this - first Noether's Theorem is a beautiful expression of how the conservation laws arise from the fundamental symmetries in the universe, one of which is the homogeneity of space from which the conservation of momentum derives. Second there are few units named after women (I assume the Curie is named after Marie and not Pierre) and Emmy Noether's personal story of a woman struggling for recognition in male-dominated European science in the early 20th century is a poignant one.
I realize there are a couple of problems with it - we need a symbol for the unit and we can't use N because Newton already has that but I'm sure we can think of something, she was Jewish so perhaps using the Hebrew equivalent (which I think is נ) although that would probably cause more problems. I think capital P might be the best since p is usually used for momentum. There is also the problem of pronunciation (it's pronounced Ner-ter). Anyway that's my pitch.
Probably not all that important but I like Emmy and I think she should get more recognition!

Friday, September 28, 2007

Brown & Thatcher

A Labour Prime-Minister shaking hands with Margret Thatcher on the steps of Downing Street? I'm kind of reminded of the end of Orwell's Animal Farm where the animals look in through the window of the farmhouse to see the pigs sitting down and having a jolly meal with the farmer they all risked their lives to throw out ... very sad