Aug. 28, 2016, 11:08 a.m.


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:


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:

Nov. 25, 2015, 9:43 a.m.



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".


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:

Thank you, Evgenii Legotckoi

Dec. 11, 2019, 4:56 p.m.

C++ - Тест 003. Условия и циклы

  • Result:50points,
  • Rating points-4
Dec. 10, 2019, 8:06 a.m.
Anastasija Troschenkova

C++ - Test 001. The first program and data types

  • Result:60points,
  • Rating points-1
Dec. 10, 2019, 8:02 a.m.
Anastasija Troschenkova

Qt - Test 001. Signals and slots

  • Result:73points,
  • Rating points1
Last comments
Dec. 9, 2019, 3:41 a.m.
Evgenij Legotskoj

Эта ошибка invalid use of incomplete type ‘class Ui::AnotherWindow’ обычно говорит о том, что не найдено определение класса или структуры. Типичная проблема - не подключён заголовочны…
Dec. 9, 2019, 3:36 a.m.
Nikolaj Batmanov

Ну, не настолько со мной всё полхо...))) Вроде бы. Я ж кнопки отрисовываю.
Dec. 9, 2019, 3:14 a.m.
Evgenij Legotskoj

Добрый день. У вас ui файлов по ходу нет. UI файлы используются для вёрстки в графическом дизайнере.
Dec. 9, 2019, 3:05 a.m.
Nikolaj Batmanov

Здравствуйте! Полностью скопировал ваш пример к себе, чтобы разобраться. А он не хочет запускаться, дает ошибку: invalid use of incomplete type ‘class Ui::AnotherWindow’ ui(new Ui…
Dec. 8, 2019, 7:23 a.m.
Evgenij Legotskoj

У меня здесь есть одна старая статья с примером векторного редактора. Там есть ответы на ваши вопросы. Поизучайте Qt/C++ - Урок 072. Пример векторного редактора на Qt QGraphicsItem, QG…
Now discuss on the forum
Dec. 11, 2019, 8:27 a.m.
Maciej Urmański

Thank you! Now works, and this is solution. num_embed = Embed.objects.filter(added_by=recipe.added_by).count()
Dec. 11, 2019, 8:12 a.m.

Так работает. Взял этот пример void MainWindow::on_pushButton_4_clicked() //фото определение лица{ // Load Face cascade (.xml…
Dec. 10, 2019, 4:14 a.m.
Timur Dosov

Спасибо, работает. А ещё вопрос: как загрузить страницу с динамической подгрузкой контента по скроллингу? Например - []. Пока делаю через костыль - QApplication::s…
Dec. 9, 2019, 7:16 a.m.

Я сделал простой вывод текста по испусканию сигнала... Чего не хватает программе?) Python: # системные библиотекиimport cv2import numpy as npimport sysimport threading# PyQt б…
Dec. 8, 2019, 4:11 p.m.
Semen Kosandjak

інтерфейс qt, приклад того додаю на малюнку, я натискаю на кнопку і у мене з'являється 2 текст лайну в які я вводжу значення, тобто в 1 цифри,у другому випадку це літери, тобто c++, без графічно…
© EVILEG 2015-2019
Recommend hosting TIMEWEB