I am using the QSqlTableModel and the QTableView. I want to be able to add and drop columns via the menubar in the GUI. When I trigger the SQL query, the db is altered as expected but the view won't update. I have to close and rerun the application to see the altered version of the db.
Here are the methods that are called when clicking on the respective entries in the menu:
def add_db_column(self):
query = QSqlQuery()
query.exec("ALTER TABLE Names ADD NewColumn varchar(255)")
query.finish()
def drop_column(self):
query = QSqlQuery()
query.exec("ALTER TABLE Names DROP NewColumn")
query.finish
I tried to include self.update(), self.model.layoutChanged.emit() and self.select() after the query in those methods, but the view just won't update.
What am I doing wrong here?