-1

我有 3 个和connect function与和pyQt相关3 signalone slotone 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))"))

我对 2 first 没有任何问题connect function,但是我得到了以下 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'

我没有任何想法Signal-Sloting,你有吗?

注意: 2首先connect functions 工作正常。

我的问题signal是,前 2和最后有什么区别signal

4

2 回答 2

1

self.tableWidget.currentItem()如果没有当前项目,则可以返回 None。在使用之前,您必须始终检查它是否不是 Nonerow()或其column()结果。此问题与您使用的信号的性质无关。

于 2013-09-26T09:45:07.403 回答
0

我解决了,与 QTableWidget 相关的信号有 2 组:

  1. 与当前时间有关
  2. 与时间无关。

在第一个选项中,我得到'NoneType' object has no attribute 'row'了用户,因为用户没有点击小部件,但在第二个选项中,我们不需要时间,也没有得到给定的traceback.

于 2013-09-26T04:46:27.883 回答