Skip to main content
Bumped by Community user
Bumped by Community user
edited tags; edited title
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Loading and writing a CSV file in a QTableView with Python 3.10 for QGIS Plugin

removed helpme and myproblemis; naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

Loading and Writingwriting a CSV-File file in a QTableView with Python 3.10 for q QGIS Plugin

I hope somebody can help me. I know there are a lot of similar questions... but I can't implement them.

So my question is how toHow can I load a CSV file and write that into a QTableView.?

myMy 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

Loading and Writing a CSV-File in a QTableView with Python 3.10 for q QGIS Plugin

I hope somebody can help me. I know there are a lot of similar questions... but I can't implement them.

So my question is how to 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

Loading and writing a CSV file in a QTableView with Python 3.10 for QGIS Plugin

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
Source Link

Loading and Writing a CSV-File in a QTableView with Python 3.10 for q QGIS Plugin

I hope somebody can help me. I know there are a lot of similar questions... but I can't implement them.

So my question is how to 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