Environment: Qt4.2 patched to use Visual Studio 2003 integration on WindowsXP

I have just ported some code to Qt4.2 and am having a problem closing the QMainWindow. When I immediately click the close window 'x' button after launch the application throws an unhandled exception. However, if I click some widgets in the workspace area and then click the main windows 'x' button the application closes as expected. I have tried overriding the QMainWindow::close() event handler, setting attributes such as WA_DeleteOnClose and various other things all to no avail. Has anyone else come across this problem before?