Error from QTableView selectionChanged
<p>If I try to get the signal when my tableview changes, Python raises this error:</p>

<pre><code>Traceback (most recent call last):
  File "UIreadresultwindow.py", line 361, in &lt;module&gt;
    ui.setupUi(ReadResultWindow)
  File "UIreadresultwindow.py", line 113, in setupUi
    self.tableEntity.selectionModel().selectionChanged.connect(self.change
_display_result)
AttributeError: 'NoneType' object has no attribute 'selectionChanged'
</code></pre>

<p>I define tableEntity as:</p>

<pre><code>self.tableEntity = QtWidgets.QTableView(self.centralWidget)
</code></pre>

<p><strong>Edit</strong>: At first my QTableView is empty. I have to open a file to fill it. </p>

<p><strong>Edit2</strong>: To be more specific, I have something like this:</p>

<pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_ReadResultWindow(object):
    def setupUi(self, ReadResultWindow):
        ReadResultWindow.setObjectName("ReadResultWindow")
        ReadResultWindow.resize(661, 438)
        self.centralWidget = QtWidgets.QWidget(ReadResultWindow)
        self.centralWidget.setObjectName("centralWidget")
        self.tableEntity = QtWidgets.QTableView(self.centralWidget)
        self.tableEntity.setObjectName("tableEntity")
        self.Open = QtWidgets.QPushButton(self.centralWidget)
        self.Open.setObjectName("Open")

        self.Open.clicked.connect(self.on_open_file)
        self.tableEntity.selectionModel().selectionChanged.connect(self.change_display_result)


    def on_open_file(self):
        x=[1,2,3,4]
        self.model= QtGui.QStandardItemModel()
        for item in x:
            self.model.invisibleRootItem().appendRow(
                QtGui.QStandardItem(str(x)))

        self.proxy= QtCore.QSortFilterProxyModel()
        self.proxy.setSourceModel(self.model)
        self.tableEntity.setModel(self.proxy)
        self.tableEntity.resizeColumnsToContents()

    def change_display_result(self,selected,deselected):
        index_entity   =  self.tableEntity.selectionModel().selectedIndexes()
        temp_entity    =  self.tableEntity.selectionModel().model()
        for index in sorted(index_entity):
            print(str(temp_entity.data(index)))

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ReadResultWindow = QtWidgets.QMainWindow()
    ui = Ui_ReadResultWindow()
    ui.setupUi(ReadResultWindow)
    ReadResultWindow.show()
    sys.exit(app.exec_())
</code></pre>

<p>you must first set the model. So you can do something like this:</p>

<pre><code>self.tableEntity = QtWidgets.QTableView(self.centralWidget)
self.tableEntity.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
</code></pre>

<p>you can set one of this models: <code>{ NoSelection, SingleSelection, MultiSelection, ExtendedSelection, ContiguousSelection }</code></p>

<p>hope this help</p>

python pyqt qtableview selectionchanged