self.tableWidget.currentItem()
can return None if there is no current item. You must always check if it is not None before using row()
or column()
on its result. This issue is not related to the nature of signals you use.
What is differences between signals for QTableWidget?
-
29-06-2022 - |
Question
I have 3 connect function
in pyQt
and are related to 3 signal
,one slot
and one widget
:
QtCore.QObject.connect(self.tableWidget, QtCore.SIGNAL(_fromUtf8("itemClicked(QTableWidgetItem*)")),
lambda: self.materialsInstance.setFilterDict_Insert("TW",self,"imported_party_attributes",0,self.tableWidget.currentItem().row(),self.tableWidget.currentItem().column()))
QtCore.QObject.connect(self.tableWidget, QtCore.SIGNAL(_fromUtf8("cellChanged(int,int)")),
lambda: self.materialsInstance.setFilterDict_Insert("TW",self,"imported_party_attributes",0,self.tableWidget.currentItem().row(),self.tableWidget.currentItem().column()))
###clear cell and remove from dict
QtCore.QObject.connect(self.tableWidget, QtCore.SIGNAL(_fromUtf8("currentCellChanged(int,int,int,int)")),
lambda: self.materialsInstance.setFilterDict_Insert("TW",self,"imported_party_attributes",0,self.tableWidget.currentItem().row(),self.tableWidget.currentItem().column()))#,"currentCellChanged(int,int,int,int))"))
I didn't any problem with 2 first connect function
, But i get the following traceback for 3th connect function
:
Traceback (most recent call last):
File "/home/mohsen/codes/amlak/amlak/src/materialsInsertFrame.py", line 244, in <lambda>
lambda: self.materialsInstance.setFilterDict_Insert("TW",self,"imported_party_attributes",0,self.tableWidget.currentItem().row(),self.tableWidget.currentItem().column()))#,"currentCellChanged(int,int,int,int))"))
AttributeError: 'NoneType' object has no attribute 'row'
I didn't any idea on Signal-Sloting
, Do you have ?
NOTE: 2 first connect functions
work fine.
My question is , What's differences between first 2 signal
and last signal
?
La solution
Autres conseils
I solved, Signals are related to QTableWidget are 2 sets:
- related to current time
- no related to time.
At first option, i user get 'NoneType' object has no attribute 'row'
because user doesn't click on widget, but in second option,We don't need time and don't get the given traceback
.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow