Correctly closing tabs and the whole program

TODO: need to get rid of redundant QSqlDatabase objects to avoid warning
about queries