I am developing a tool is Qgis3 using PyQt5. I am adding columns using a button and the setting column names using 'setHorizontalHeaderItem'. But it gives None while trying to read it. Following is the code.
count=self.dlg.tableWidget.columnCount()
self.dlg.tableWidget.setColumnCount(count+1)
header= QTableWidgetItem(str(count+1))
self.dlg.tableWidget.setHorizontalHeaderItem(count+1,header)
self.dlg.lineEdit_4.setText(self.dlg.tableWidget.horizontalHeaderItem(count+1).text())
it gives an error- 'AttributeError: 'NoneType' object has no attribute 'text' ' I can't identify the mistake.