Qt → Qt/C++ - Lesson 054. Reading data from a CSV file, and their representation via QStandardItemModel
CSV, QStandardItemModel, Qt, QTableView
CSV data format ( Comma-Separated Values ) format is the simplest representation of tabular data. This format is supported by Excel and many other office suites. For example, I often encounter this format when uploading statistics do the site of the panel webmasters Google Search Console.
In this format, the table represents the data sequence, separated by commas, and represent the column and row are separated by a newline. In the case of the Russian-language Microsoft Excel data separated by semicolons and will be as follows:
BMW;X5;3000000 Lada;Kalina;250000
Parsing CSV
So the whole problem is reduced to a line reading data from a file and uploads the data model of data presentation, which will be placed in QTableView .
Let us take as a basis the above example, the contents of a CSV file that was created in Microsoft Excel:

And display it in QTableView via QStandardItemModel:

QML → QML - Lesson 017. Export data into CSV format from data model in QML Qt
In that case, if you need to unload the table data from an application to a CSV file, the interface is more and is written in the QML, then hasten to this article, to give a little hint.
For example, in an article on work with SQLite database in the annex to the QML database was created, to which is added the data and removed from it. At the same time they appear in the TableView, which was already part of the interface written in QML. And to display the table used by the data model to inherit from QSqlQueryModel .
I propose to use the source code of the project and expand it so that there was a button in the application to export data to a CSV file.
What is a CSV format
CSV ( Comma-Separated Values ) — text format for presenting tabular data. Each line of the file - this is one line of the table. The values of individual columns are separated by a separating character (delimiter) - a comma (,). However, most of the programs is free treats CSV standard and allow the use of other characters as the delimiter.
In general, the essence of the work is reduced to ensure a method to our data model that will pull data from this model and a semicolon each cell in the row, and each row share a newline character "\ n".
Donate
Hello, Dear Users of EVILEG!!!
If the site helped you, then support the development of the site financially, please.
You can do it by following ways:
- PayPal
- Yandex.Money
- Bitcoin: 13aqaPG8NZhX3By3he9LtrnHsmvRgsbt95
- Patreon - in Patreon I wrote my targets for reducing of advertisements on the site
Thank you, Evgenii Legotckoi