first commit, with minor modifications for multi-thread qt.