QSql refresh()?
-
As far as I can see you are asking this question again and again and again. If you use the search function in this forum you could find an answer
here for example (you did post in there too)
-
Please don't post the same question multiple times! It's shows disrespect to the people trying to help you on their own time. Stick to your original thread and provide more information, or ask additional related questions there.
Consider yourself warned. -
@the_ how to use this code?
'''
QString queryStr = model->query().executedQuery();
model->clear();
model->query().clear();
model->setQuery(queryStr);with this code? because this is the way i refresh a table is this bad?
import sys
import os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSql import *
from PyQt4 import QtGui,QtCore
import mysql.connectorclass Window(QtGui.QMainWindow):
def init(self):
super(Window, self).init()
self.setGeometry(50,50,500,300)
self.setWindowTitle("Inventory and Monitoring System")
self.setWindowIcon(QtGui.QIcon('Pictures/delta.png'))
QApplication.setStyle(QStyleFactory.create('Cleanlooks'))self.db = QSqlDatabase.addDatabase("QMYSQL") self.db.setHostName("localhost") self.db.setDatabaseName("incoming_mac") self.db.setUserName("root") self.db.setPassword("admingelo") self.db.open() self.Date_received = QLineEdit(self) self.searchbtn = QtGui.QPushButton("SUBMIT",self) self.searchbtn.clicked.connect(self.Database) self.searchbtn.move(10,50) self.searchbtn1 = QtGui.QPushButton("REFRESH",self) self.searchbtn1.clicked.connect(self.RefreshTable) self.searchbtn1.move(10,90) self.show() def Database(self): DATE_RECEIVED = self.Date_received.text() self.con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="incoming_mac") self.manager = self.con.cursor() self.insert_this_data = ("""INSERT INTO incoming_mac_records(DATE_RECEIVED) VALUES('%s')"""%str(DATE_RECEIVED)) self.manager.execute(self.insert_this_data) self.con.commit() self.con.close() def RefreshTable(self): self.projectModel = QSqlQueryModel() self.projectModel.setQuery("select * from incoming_mac_records",self.db) self.projectView = QTableView(self) self.projectView.setModel(self.projectModel) self.projectView.resizeColumnsToContents() self.projectView.setGeometry(50,50,300,200) self.projectView.show()
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run() -
@the_ IS THIS CODE OKAY? IF I WANT TO REFRESH A TABLE EVERY 3 OR MORE SECONDS?
import sys
import time
import osx = 0
while x != 3:
x+=1
print (x)
#
'''
AND THE FUNCTION HERE TO REFRESH EVERY 3 OR MORE SECONDS?
'''
#
time.sleep(2)
if x >= 3:
x = 0 -
@BjornW for you it is. Maybe your an expert in coding that's why you are so boastful i am asking because i want to understand what i ask not to tell a joke
don't you worry next time i will try to ask "How to handle Overconfident people"
-
Model is the QSqlQueryModel of your QTableView