Port most of the code to the Qt4