I am starting to learn Qt for python and, as I was interested after reading this post:
qt-pyqt QTableView does not populate when changing databases. If there was a way to use SQLAlchemy sessions instead of (re) opening a database connection as a table model with a Qt QTableView widget.
Something that will work something like this:
databasePath = "base.sqlite"
engine = create_engine('sqlite:///' + databasePath, echo=True)
Session = sessionmaker(bind=engine)
session = Session()
self.setupUi(self)
self.model = QSqlTableModel(self)
self.model.setTable("records")
self.model.setSort(FILEORDER, Qt.AscendingOrder)
self.model.setHeaderData(ID, Qt.Horizontal, QVariant("ID"))
self.model.setHeaderData(NAME, Qt.Horizontal, QVariant("Name"))
self.model.select()
self.tableView.setModel(self.model)
Any help would be greatly appreciated, as well as new ways to think about this issue.
thank
source
share