Python 激活QShortcut时PyQt粘贴函数类型错误

Python 激活QShortcut时PyQt粘贴函数类型错误,python,qt,pyqt,typeerror,paste,Python,Qt,Pyqt,Typeerror,Paste,我已经成功地尝试了PyQt粘贴函数。然后我在init函数中对其进行了如下修改: def __init__(self): .... self.initShortcuts() .... def initShortcuts(self): self.shortcutPaste = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_V), self) self.shortcutPaste.setContext(Qt.WidgetShortcut) s

我已经成功地尝试了PyQt粘贴函数。然后我在init函数中对其进行了如下修改:

def __init__(self):
  ....
  self.initShortcuts()
  ....
def initShortcuts(self):
  self.shortcutPaste = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_V), self)
  self.shortcutPaste.setContext(Qt.WidgetShortcut)
  self.shortcutPaste.activated.connect(self.__handlePaste())

def __handlePaste(self):
  clipboard = QtGui.QApplication.instance().clipboard().text()

  rows = clipboard.split('\n')
  numRows = len(rows) - 1
  cols = rows[0].split('\t')
  numCols = len(cols)

  for row in xrange(numRows):
    columns = rows[row].split('\t')
    for col in xrange(numCols):
      item = QTableWidgetItem(u"%s" % columns[col])
      self.tblTransMatrix.setItem(row, col, item)
  ...
这是使用Ctrl+V快捷键并连接到处理从剪贴板粘贴到QTableWidget函数的initShortcuts函数的代码段:

def __init__(self):
  ....
  self.initShortcuts()
  ....
def initShortcuts(self):
  self.shortcutPaste = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_V), self)
  self.shortcutPaste.setContext(Qt.WidgetShortcut)
  self.shortcutPaste.activated.connect(self.__handlePaste())

def __handlePaste(self):
  clipboard = QtGui.QApplication.instance().clipboard().text()

  rows = clipboard.split('\n')
  numRows = len(rows) - 1
  cols = rows[0].split('\t')
  numCols = len(cols)

  for row in xrange(numRows):
    columns = rows[row].split('\t')
    for col in xrange(numCols):
      item = QTableWidgetItem(u"%s" % columns[col])
      self.tblTransMatrix.setItem(row, col, item)
  ...
但它给了我以下错误:

TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'

您正试图将方法的返回值传递给connect,此时您应该传递可调用对象本身,即不带括号:

    self.shortcutPaste.activated.connect(self.__handlePaste)

看起来uu handlePaste没有返回任何值。我们至少能看到这个函数的其余部分吗?噢,我忘了去掉括号了!谢谢你的帮助