Threading fixes

These fix problems found by running with QT_FATAL_WARNINGS turned on. On Windows the threading bugs were causing crashes. This should fix Issue #827 also the QTimer issues reported on qoogle groups.