Что нетак с кодом почему он не сохраняет а выводит QVariant::save: unable to save type 'QObject*' (type id: 39).
#import subprocess
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QSize, QCoreApplication, QSettings
from food import Ui_MainWindow
ORGANIZATION_NAME = 'Example App'
ORGANIZATION_DOMAIN = 'example.com'
APPLICATION_NAME = 'QSettings program'
SETTINGS_TRAY = 'settings/tray'
class MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, rows):
super(MyWindow, self).__init__()
self.rows = rows
self.setupUi(self)
self.pushButton.clicked.connect(self.set_row_count)
self.tableWidget.cellChanged.connect(self.cell_changed)
self.tableWidget_2.cellChanged.connect(self.cell_changed_2)
self.pushButton_2.clicked.connect(self.save_table_settings)
settings = QSettings()
def save_table_settings(self):
settings = QSettings()
settings.setValue(SETTINGS_TRAY, self.tableWidget)
settings.sync()
def set_row_count(self):
self.rows += 1
self.tableWidget.setRowCount(self.rows)
self.tableWidget_2.setRowCount(self.rows)
def cell_changed(self, row, column):
_sum = 0
if column == 2:
if self.tableWidget.item(row, column) != None:
try:
_sum += int(self.tableWidget.item(row, column).text())
except:
pass
_bud = 0
if self.tableWidget.item(row, 1) != None:
try:
_bud = int(self.tableWidget.item(row, 1).text())
except:
pass
ost = _bud - _sum
self.tableWidget.setItem(row, 3, QtWidgets.QTableWidgetItem(str(ost)))
def cell_changed_2(self, row, column):
_sum = 0
if 0 < column < 6:
for column in range(1, 5):
if self.tableWidget_2.item(row, column) != None:
try:
_sum += int(self.tableWidget_2.item(row, column).text())
except:
pass
_lgota = 0
if self.tableWidget_2.item(row, 5) != None :
try:
_lgota = int(self.tableWidget_2.item(row, 5).text())
except:
pass
ost = _sum - _lgota
self.tableWidget_2.setItem(row, 6, QtWidgets.QTableWidgetItem(str(ost)))
self.tableWidget.setItem(row, 2, QtWidgets.QTableWidgetItem(str(ost)))
number_rows = 1
if __name__ == '__main__':
import sys
QCoreApplication.setApplicationName(ORGANIZATION_NAME)
QCoreApplication.setOrganizationDomain(ORGANIZATION_DOMAIN)
QCoreApplication.setApplicationName(APPLICATION_NAME)
app = QtWidgets.QApplication(sys.argv)
w = MyWindow(number_rows)
w.show()
sys.exit(app.exec_())