使用python在pyqt中显示从sql到tableview的数据

时间:2017-01-06 14:03:32

标签: mysql pyqt tableview rfid qtcore

我在pyqt中太新了,现在我有一个Raspberry Pi和pyqt的项目
在项目中我想显示从sql到tableview的数据
这是代码

import sys
import RPi.GPIO as GPIO
import time
import re    
import signal    
import MFRC522    
from PyQt4 import uic, QtCore, QtGui    
from PyQt4.QtCore import *    
from PyQt4.QtSql import *
from PyQt4.QtGui import *

GPIO.setwarnings(False) #Disables the Warning

db = QSqlDatabase.addDatabase("QMYSQL")
db.setDatabaseName("daftar")
db.setUserName("root")
db.setPassword("asdasd")
db.open()

permintaan = QSqlQuery()
permintaan.exec_("select * from data_aben")
lanjut=permintaan.next()
a=0
sql_data = permintaan.value(0).toString()

class test_absen(QtGui.QMainWindow):
        def __init__(self):
                super(test_absen, self).__init__()
                uic.loadUi('test_absen.ui',self)
                MIFAREReader = MFRC522.MFRC522()
                timer = QtCore.QTimer(self)
                timer.timeout.connect(self.timout)
                timer.start(1)

        def timout(self):
                MIFAREReader = MFRC522.MFRC522()
                (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
                (status,uid) = MIFAREReader.MFRC522_Anticoll()
                lanjut=permintaan.next()
               c = permintaan.value(0).toString()
                self.mysqldata.setText(c)
                if status == MIFAREReader.MI_OK:
                        key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
                        a = str(uid[0]) + str(uid[1]) + str(uid[2]) + str(uid[3])
                        self.lineEdit.setText(a)
                        if str(a) == permintaan.value(0).toString() :
                                nama = permintaan.value(2).toString()
                                nim = permintaan.value(1).toString()
                                self.label.setText(nama)
                                self.output.setText(nim)

if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
        MainWindow = QtGui.QMainWindow()
        window = test_absen()
        window.show()
        sys.exit(app.exec_())`

现在你的问题是如何从sql到table view显示数据 我真的希望得到帮助 抱歉英语不好:D 先于

0 个答案:

没有答案