Unsolved setTable line fails: QSqlTableModel: THIRD DEADLINE HAS PASSED HELPPPP!!
-
Hi All,
I have been trying for a while to use an SQL database and display on GUI using PYQT5.
I am trying to create an interface where users will enter an event, a date and a time. I want these to be inserted into row of MySQL table.I was able to establish connection to database
db.open() shows true. but when try to create table model it crashes at line setTable(""). when I comment this line rest of code runs and empty window opens.PLEASE PLEASE PLEASE HELP
see sample code below:
def createConnection():
db = QtSql.QSqlDatabase().addDatabase("QMYSQL")
db.setHostName("Y3tti")
db.setDatabaseName("banshe")
db.setUserName("user")
db.setPassword("password")
print("sec conn")
print(db.open())class thirdwindow(QtWidgets.QMainWindow):
def init(self, parent=None):
super(thirdwindow, self).init(parent)
createConnection()
self.initUI()def initUI(self): print('initui') mod = QtSql.QSqlTableModel(self) mod.setTable("event_record") print(mod.lastError().text()) print('after set table') mod.setHeaderData(0, QtCore.Qt.Horizontal, "event_id") mod.setHeaderData(1, QtCore.Qt.Horizontal, "event_name") mod.setHeaderData(2, QtCore.Qt.Horizontal, "done_by") print('hello') mod.select() mod.rowCount() view1 = QtWidgets.QTableView(self) view1.setModel(mod) self.setCentralWidget(view1) self.show()
-
Hi and welcome to devnet,
You should add which version of Qt your are using as well as PyQt and OS.
Also, what stack trace do you get when your application crashes ?