【发布时间】:2015-07-10 06:18:15
【问题描述】:
table = QTableView()
model = QStandardItemModel()
table.setModel(model)
r = table.model().rowCount()
c = table.model().columnCount()
tLeft = table.model().index(0, 0)
bRight = table.model().index(r, c)
table.dataChanged(tLeft, bRight).connect(SomeFunction)
AttributeError: 'NoneType' object has no attribute 'connect'
目标 - 当 QTableView() 中的用户直接更改其中一项时调用 SomeFunction。
我做错了什么?我看到 NoneType 对象不能有属性 connect,但为什么它是 NoneType。
请发表评论。我是初学者。 Qt5.
【问题讨论】:
-
看起来函数
table.dataChanged(tLeft, bRight)返回None。应该从table对象调用connect方法吗? (这只是猜测,我没用过Qt5) -
如果我把它应用到像
table.model().dataChanged(tLeft, bRight).connect(SomeFunction)这样的模型上,它会说TypeError: native Qt signal is not callable -
您查看文档了吗?你的哪些对象有
connect方法?你见过它工作的例子吗? -
进一步阅读:PyQt5 signals and slots。对于 PyQt4 及之前的版本,还有另一种连接信号和插槽的方式,但在 PyQt5 中不再支持。
标签: python qt pyqt qtableview