'Python 3 Streams in PySide2
please help me figure out the threads in PySide2!
I can't understand it at all...
I want to make it so that when the window is opened, the processes are executed in parallel and the table is filled in as the functions work. However, where and no matter how I insert QThread, my_signal and QThread.start() - there is very little sense.
Code:
import time
class Qthre(QtCore.QThread):
def __init__(self, parent=None):
super(Qthre, self).__init__(parent)
self.value = 0
def run(self):
def CkeckFileInBase():
Base = sqlite3.connect(r"wowlist.db", uri=True)
Base.row_factory = sqlite3.Row
Cur = Base.cursor()
s = 'SELECT * FROM files'
Cur.execute(s)
records = Cur.fetchall()
spisok_zla = []
spisok_zla2 = []
for row in records:
c = CkeckHash(row[0], row[1])
if c:
pass
else:
if os.path.exists(row[0]):
h1 = DeShifroHash(row[1])
newH = HashCal(row[0])
spisok_zla.append((row[0], h1, newH))
else:
spisok_zla2.append((row[0], h1, 'File not found'))
return spisok_zla
spisok_zla = CkeckFileInBase()
data = []
for item in spisok_zla:
mtime = os.path.getmtime(item[0])
dataIzm = datetime.datetime.strptime(time.ctime(mtime), "%a %b %d %H:%M:%S %Y")
dataIzm = str(dataIzm.strftime('%H:%M:%S %d/%m/%Y'))
data.append((item[0], str(item[2]), str(item[1]), dataIzm))
return data
def MainWindow():
loader = QUiLoader()
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
app.setQuitOnLastWindowClosed(True)
else:
app = QtWidgets.QApplication.instance()
app.setQuitOnLastWindowClosed(True)
...
def winCheck():
"""окно проверки файлов из базы данных"""
winCh = loader.load("ui\\check.ui", window)
# Получаем список файлов
#data = SpisokZlaForTable()
Qthre1 = Qthre(winCh)
Qthre1.start()
data = Qthre1.run()
print(data)
# заполняем таблицу
#winCh.tbIzmFiles.setGeometry(QtCore.QRect(0, 60, 781, 291))
#winCh.tbIzmFiles.setGeometry(QtCore.QRect(0, 60, 781, 291))
#winCh.tbIzmFiles.setRowCount(len(data))
winCh.tbIzmFiles.setColumnCount(4)
winCh.tbIzmFiles.setHorizontalHeaderLabels( # проверь, что не напутал с хешами
('Файл:', 'новый Хеш:', 'старый Хеш:', 'Дата изменения:')
)
row = 0
for tup in data:
col = 0
for item in tup:
cellinfo = QtWidgets.QTableWidgetItem(item)
cellinfo.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled
)
winCh.tbIzmFiles.setItem(row, col, cellinfo)
col += 1
row += 1
winCh.tbIzmFiles.resizeColumnsToContents()
winCh.tbIzmFiles.setColumnWidth(1, 200)
winCh.tbIzmFiles.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
# Показать окно
winCh.show()
window.pbCheck.clicked.connect(winCheck)
...
window.show()
# window.update()
app.exec_()
MainWindow()
How and where to use QThread in here? I've already read about it and still can't understand anything
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
