I know there are a lot of similar questions... but I can't implement them.
How can I load a CSV file and write that into a QTableView?
My first step was to browse it.
def select_input_file(self):
filename, _filter = QFileDialog.getOpenFileName(
self.dlg, "Select input file ","",
("GeoPackages (*.gpkg);;Comma separated values (*.csv);;Shapefiles (*.shp)")
)
self.dlg.Input_Box.setText(filename)
In the next step, I want to load it and write it in the QTableView called table.
def show(self):
self.table = QtGui.QStandardItemModel(self)
filename = self.dlg.Input_Box.text()
with open(filename, "r") as fileInput:
for row in csv.reader(fileInput):
items = [
QtGui.QStandardItem(field)
for field in row
]
self.table.appendRow(items)
But I get this error:
self.table = QtGui.QStandardItemModel(self)
TypeError: arguments did not match any overloaded call:
QStandardItemModel(parent: QObject = None): argument 1 has unexpected type 'GTool'
QStandardItemModel(int, int, parent: QObject = None): argument 1 has unexpected type 'GTool'
These packages are loaded:
from PyQt5 import QtCore, QtGui, QtWidgets
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QApplication, QWidget, QTableWidget, QTableWidgetItem, QFileDialog, QDialog, QPushButton, QDialogButtonBox, QLineEdit
from qgis.core import QgsProject, Qgis
from qgis.utils import iface