call to endProcessMessages has been added before getting disconnected in MainWindow::disconnectClicked() - we have to end processMessages() loop in POSIX thread before  getting disconnected because otherwise we don't stop POSIX thread in MainWindow destructor before exiting if we are not connected. Now we can close and reopen connection without any issues