(SOLVED)Qtimer Call Help
-
I am trying to make an app, using python and pyside, that will display the first 10 rows of data from a mysql db table to the screen and then display the next set of 10 rows 30 seconds later. I think I have all the coding done that I need to make the initial display happen properly, but it never refreshes with the new query. I am certain it is because I am calling the method incorrectly or putting the timer call in the wrong spot or even opening and executing the app incorrectly, but I cant seem to get it right. Brand new to Python and programming in general. Any help is greatly appreciated. Heres what I have so far:
@from PySide import QtGui, QtSql, QtCore
import sysclass myDisplay:
def connectDB(self):
self.db=QtSql.QSqlDatabase.addDatabase("QMYSQL")
self.db.setHostName("localhost")
self.db.setDatabaseName("db")
self.db.setUserName("user")
self.db.setPassword("pw")def makeModel(self, table):
self.model=QtSql.QSqlTableModel()
self.model.setTable("'" + table + "'")
self.model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)def createQuery(self, query1):
self.query=QtSql.QSqlQuery(query1)
self.model.setQuery(self.query)def setHeaders(self, *params):
self.model.setHeaderData(0, QtCore.Qt.Horizontal, params[0])
self.model.setHeaderData(1, QtCore.Qt.Horizontal, params[1])
self.model.setHeaderData(2, QtCore.Qt.Horizontal, params[2])
self.model.setHeaderData(3, QtCore.Qt.Horizontal, params[3])
self.model.setHeaderData(4, QtCore.Qt.Horizontal, params[4])
self.model.setHeaderData(5, QtCore.Qt.Horizontal, params[5])
self.model.setHeaderData(6, QtCore.Qt.Horizontal, params[6])
self.model.setHeaderData(7, QtCore.Qt.Horizontal, params[7])
self.model.setHeaderData(8, QtCore.Qt.Horizontal, params[8])
self.model.setHeaderData(9, QtCore.Qt.Horizontal, params[9])
self.model.setHeaderData(10, QtCore.Qt.Horizontal, params[10])
if params[11] in locals():
self.model.setHeaderData(11, QtCore.Qt.Horizontal, params[11])
else:
return "no11"
if params[12] in locals():
self.model.setHeaderData(12, QtCore.Qt.Horizontal, params[12])
else:
return "no12"
if params[13] in locals():
self.model.setHeaderData(13, QtCore.Qt.Horizontal, params[13])
else:
return "no13"
if params[14] in locals():
self.model.setHeaderData(14, QtCore.Qt.Horizontal, params[14])
else:
return "no14"
if params[15] in locals():
self.model.setHeaderData(15, QtCore.Qt.Horizontal, params[15])
else:
return "no15"def makeApp(self, appName):
self.app = QtGui.QApplication(sys.argv)
self.app.setApplicationName("app")def makeForm(self):
self.form = QtGui.QTableView()
self.form.setModel(self.model)
self.font = QtGui.QFont("Arial", 24, QtGui.QFont.Bold)
self.form.setFont(self.font)
self.form.resizeColumnsToContents()
self.form.resizeRowsToContents()
self.form.verticalHeader().setVisible(False)
self.form.setObjectName("form")
self.form.setAlternatingRowColors(True)
self.form.showFullScreen()def run(self):
self.form.show()
sys.exit(self.app.exec_())def timer(self, milliseconds):
self.timer=QtCore.QTimer()
self.timer.setInterval(milliseconds)
self.timer.start()
self.timer.timeout,connect(self.app.close())x=myDisplay()
x.connectDB()
x.makeModel("table")
x.createQuery("SELECT field1, field2, field3, field4 FROM table ORDER BY field 4 DESC LIMIT 10")
x.setHeaders("Field 1", "Field 2", "Field 3", "Field 4")
x.makeApp("app")
x.makeForm()
x.run()
x.timer(30000)y=myDisplay()
y.connectDB()
y.makeModel("table")
y.createQuery("SELECT field1, field2, field3, field4, field5 FROM table ORDER BY field4 DESC LIMIT 10,10")
y.setHeaders("Field 1", "Field 2", "Field 3", "Field 4", "Field 5")
y.makeApp("app")
y.makeForm()
y.run()
y.timer(30000)next set would go here, etc
@
-
Hi,
You are starting your timer after calling run which starts the event loop and exits the program when done thus it's never started in the first place.
Hope it helps
-