I try to get data from LineEdit text giving to SQLite but i got below error and i get 1 problem that SQLite auto get "" text , eventhough GUI dont appear for me to type into EditLine
QSocketNotifier: Can only be used with threads started with QThread
[('', '', 'Male', '<built-in method text of QLineEdit object at 0x7fc496171040>')]
Traceback (most recent call last):
File "/home/baoduy/Desktop/GUI/run.py", line 35, in <module>
main_win = UI()
File "/home/baoduy/Desktop/GUI/run.py", line 16, in __init__
self.Dktt = Dangkithongtin()
File "/home/baoduy/Desktop/GUI/Dangkithongtin.py", line 29, in __init__
self.btnDangkithongtin.clicked.connect(self.INSERT_NOIDUNG(ID,Name,Gender,Birthday))
TypeError: argument 1 has unexpected type 'NoneType'
from PyQt5 import uic
from Dktt import Ui_dkttWindow
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableWidgetItem
from classdb import *
from PyQt5.QtCore import QDate, QTime, QDateTime, Qt
mydb = MY_DB()
class Dangkithongtin(QMainWindow):
global mydb
def __init__(self):
super().__init__()
uic.loadUi("Dktt.ui",self)
self.tableDulieu.setColumnWidth(0,70)
self.tableDulieu.setColumnWidth(1,200)
self.tableDulieu.setColumnWidth(2,120)
self.tableDulieu.setColumnWidth(3,180)
mydb.connect2()
#mydb.create_table1()
ID = self.txtbID.text()
Name = self.txtbName.text()
Gender = str(self.combGender.currentText())
Birthday = self.txtbBirthday.text
self.btnDangkithongtin.clicked.connect(self.INSERT_NOIDUNG(ID,Name,Gender,Birthday))
#self.btnDangkithongtin.clicked.connect(self.INSERT_NOIDUNG("3","4","5","6"))
#self.btnChinhsua.clicked.connect(self.Chinhsuadangki(Name,ID,Gender,Birthday))
def SHOWDB(self):
self.result = mydb.select_all()
print(self.result)
#show ảnh : truyền dữ liệu từ sql vào GUI bằng hàm setItem
self.tableDulieu.setRowCount(0) #bắt đầu Row là dòng 0
for row_num,row_data in enumerate(self.result):
self.tableDulieu.insertRow(row_num) # thêm vào dòng mới
for col_num, col_data in enumerate(row_data):
self.tableDulieu.setItem(row_num,col_num,QTableWidgetItem(str(col_data)))
# truyền vào stt cột và stt hàng , và dữ liệu QTableWidgetItem(str(col_data) dưới dạng str
def INSERT_NOIDUNG(self,ID,Name,Gender,Birthday):
#mydb.insert_row_data("{ID}".format(ID=ID),"{Name}".format(Name=Name),"{Gender}".format,"{Birthday}",format(Birthday=Birthday))
mydb.insert_row_data(f"{ID}",f"{Name}",f"{Gender}",f"{Birthday}")
self.SHOWDB()
CodePudding user response:
The argument to connect()
should be a function to call, not a call to the function. Use lambda
to call self.INSERT_NOIDUNG()
self.btnDangkithongtin.clicked.connect(lambda: self.INSERT_NOIDUNG(ID,Name,Gender,Birthday))