Handling CSV: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Convert ExpressionEngine links)
(fix links and code)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{LangSwitch}}
 
This page discusses various available options for working with [http://en.wikipedia.org/wiki/Comma-separated_values csv] documents in your Qt application. Please also read the general considerations outlined on the [[Handling Document Formats]] page.
h1. Handling CSV (file format)
 
This page discusses various available options for working with [http://en.wikipedia.org/wiki/Comma-separated_values csv] documents in your Qt application. Please also read the general considerations outlined on the [http://wiki.qt.io/Handling_Document_Formats Handling Document Formats] page.


== Using QxtCsvModel ==
== Using QxtCsvModel ==
Line 9: Line 6:
=== intro ===
=== intro ===


The [http://libqxt.bitbucket.org/doc/tip/qxtcsvmodel.html QxtCsvModel] class provides a [http://doc.qt.io/qt-5.0/qtcore/qabstracttablemodel.html QAbstractTableModel] for CSV Files. This is perhaps the easiest way possible to read and write csv files without having to parse the csv format to something qt can understand. It's as simple as using one line of code, for example the following reads the csv file:
The [https://libqxt.bitbucket.io/doc/0.6/qxtcsvmodel.html QxtCsvModel] class provides a {{DocLink|QAbstractTableModel}} for CSV Files. This is perhaps the easiest way possible to read and write csv files without having to parse the csv format to something qt can understand. It's as simple as using one line of code, for example the following reads the csv file:


<code>
<code>
Line 17: Line 14:
=== Building libqxt ===
=== Building libqxt ===


QxtCsvModel is a part of [http://dev.libqxt.org/libqxt/wiki/Home libqxt] so just to use QxtCsvModel you'll need to build this library. It won't be that hard. Instructions are all provided. However, the download link that they provide in their main page does not support Qt 5 as of this writing(23/4/2013). You'll need to go [http://dev.libqxt.org/libqxt/downloads here] , select the "branches" tab and download the zip file of the master branch.
QxtCsvModel is a part of [https://libqxt.bitbucket.io/doc/0.6/index.html libqxt] so just to use QxtCsvModel you'll need to build this library. It won't be that hard. Instructions are all provided. However, the download link that they provide in their main page does not support Qt 5 as of this writing (23 April 2013). You'll need to go to the [http://dev.libqxt.org/libqxt/downloads downloads page], select the "branches" tab and download the zip file of the master branch.


A novice friendly step by step guide in building and getting libqxt to work in written [http://wiki.qt.io/LibQxt_in_QtCreator here] The following example will be using the build as done in that guide.
A novice-friendly step-by-step guide to building and getting libqxt to work can be found [[LibQxt in QtCreator|here]]. The following example will be using the build as done in that guide.


=== Example: Mini csv Program ===
=== Example: Mini csv Program ===
[[Image:https://lh3.googleusercontent.com/-b5m3QxX8pyM/UXoGGXu2_lI/AAAAAAAABP4/7rkLeGfcEuY/w587-h293/_2013-04-26_12-43-19.png|minicsvprogram]]


[https://bitbucket.org/bruceoutdoors/mini-qt-csv-example Mini csv program] is built with Qt 5.0.2 MinGW, but should probably work with Qt 4. [https://bitbucket.org/bruceoutdoors/mini-qt-csv-example/get/master.zip Download from here] . The only thing you would need to do to get it working is fix the links to the dynamic library. I built it in C:/Qt/libqxt-libqxt-Qt5/ so I directed it there. Below is a snipet of the project file:
[https://bitbucket.org/bruceoutdoors/mini-qt-csv-example Mini csv program] is built with Qt 5.0.2 MinGW, but should probably work with Qt 4. [https://bitbucket.org/bruceoutdoors/mini-qt-csv-example/get/master.zip Download from here] . The only thing you would need to do to get it working is fix the links to the dynamic library. I built it in C:/Qt/libqxt-libqxt-Qt5/ so I directed it there. Below is a snipet of the project file:


<code>
<code>
win32:CONFIG (release, debug|release): LIBS ''= -LC:/Qt/libqxt-Qt5/lib/ -lqxtcore
win32:CONFIG (release, debug|release): LIBS += -LC:/Qt/libqxt-Qt5/lib/ -lqxtcore
else:win32:CONFIG (debug, debug|release): LIBS''= -LC:/Qt/libqxt-Qt5/lib/ -lqxtcore
else:win32:CONFIG (debug, debug|release): LIBS += -LC:/Qt/libqxt-Qt5/lib/ -lqxtcore


INCLUDEPATH ''= C:/Qt/libqxt-Qt5/src/core
INCLUDEPATH += C:/Qt/libqxt-Qt5/src/core
DEPENDPATH''= C:/Qt/libqxt-Qt5/src/core
DEPENDPATH += C:/Qt/libqxt-Qt5/src/core
</code>
</code>
Well, you're also suppose to add the following lines to your qmake project file:
Well, you're also suppose to add the following lines to your qmake project file:
<code>
<code>
  CONFIG ''= qxt
  CONFIG += qxt
  QXT''= core gui
  QXT += core gui
</code>
</code>
…but it doesn't seem to make much of a difference here… or any of the examples I've tried…
…but it doesn't seem to make much of a difference here… or any of the examples I've tried…

Latest revision as of 17:37, 9 March 2017

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

This page discusses various available options for working with csv documents in your Qt application. Please also read the general considerations outlined on the Handling Document Formats page.

Using QxtCsvModel

intro

The QxtCsvModel class provides a QAbstractTableModel for CSV Files. This is perhaps the easiest way possible to read and write csv files without having to parse the csv format to something qt can understand. It's as simple as using one line of code, for example the following reads the csv file:

csvmodel->setSource(fileName);

Building libqxt

QxtCsvModel is a part of libqxt so just to use QxtCsvModel you'll need to build this library. It won't be that hard. Instructions are all provided. However, the download link that they provide in their main page does not support Qt 5 as of this writing (23 April 2013). You'll need to go to the downloads page, select the "branches" tab and download the zip file of the master branch.

A novice-friendly step-by-step guide to building and getting libqxt to work can be found here. The following example will be using the build as done in that guide.

Example: Mini csv Program

Mini csv program is built with Qt 5.0.2 MinGW, but should probably work with Qt 4. Download from here . The only thing you would need to do to get it working is fix the links to the dynamic library. I built it in C:/Qt/libqxt-libqxt-Qt5/ so I directed it there. Below is a snipet of the project file:

win32:CONFIG (release, debug|release): LIBS += -LC:/Qt/libqxt-Qt5/lib/ -lqxtcore
else:win32:CONFIG (debug, debug|release): LIBS += -LC:/Qt/libqxt-Qt5/lib/ -lqxtcore

INCLUDEPATH += C:/Qt/libqxt-Qt5/src/core
DEPENDPATH += C:/Qt/libqxt-Qt5/src/core

Well, you're also suppose to add the following lines to your qmake project file:

 CONFIG += qxt
 QXT += core gui

…but it doesn't seem to make much of a difference here… or any of the examples I've tried…

I can now call the class like so:

#include <QxtCsvModel>

The functionality provided is very very basic. If you wish to probe deeper to what this class can do, check the QxtCsvModel documentation .

CSV reader from QtSimplify(Read CSV Only)

http://qtsimplify.blogspot.com/2013/02/dealing-with-csv-files-easy-way.html