Hi everyone,
i'm starting to learn Qt for python and as i was wondering after reading this post : qt - pyqt QTableView not populating when changing databases. if there was a way to use SQLAlchemy sessions instead of (re-)opening a database connection as a Table Model with Qt's QTableView widget.
Something that would work a little bit like that :
databasePath = "base.sqlite" # used for production
engine = create_engine('sqlite:///' + databasePath, echo=True)
# initializing session :
Session = sessionmaker(bind=engine)
session = Session()
# Set up the user interface from Designer.
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 problem.
Thank you