2015-07-10 65 views
0
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'table.dataChanged(索引,索引)。将(someFunction)失败

目标 - 调用SomeFunction时的项目之一直接由用户在QTableView()改变。

我该怎么做?我看到NoneType对象不能具有属性连接,但它为什么是NoneType。

请评论。我是一名初学者。 QT5。

+0

它看起来像函数table.dataChanged(tLeft,bRight)返回的是None。应该从'table'对象调用'connect'方法吗? (这只是一个猜测,我从来没有使用过Qt5) –

+0

如果我将它应用于像'table.model()。dataChanged(tLeft,bRight).connect(SomeFunction)'这样的类型错误:原生Qt信号不可调用' –

+0

你检查过文档吗?哪些对象具有'connect'方法?你见过它的一个例子吗? –

回答

1

你应该这样做:

table.model().dataChanged.connect(someFunction) 
# or model.dataChanged.connect(someFunction) 

不需要精确的参数。该插槽应如下所示:

def someFunction(tLeft,bRight): 
    #do stuff