Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Handling CSV
Handling CSV
This page discusses various available options for working with csv [en.wikipedia.org] documents in your Qt application. Please also read the general considerations outlined on the Handling Document Formats [qt.io] page.
Using QxtCsvModel
intro
The QxtCsvModel [libqxt.bitbucket.org] class provides a QAbstractTableModel [qt.io] 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:
Building libqxt
QxtCsvModel is a part of libqxt [dev.libqxt.org] 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 here [dev.libqxt.org] , 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 here [qt.io] The following example will be using the build as done in that guide.
Example: Mini csv Program
Mini csv program [bitbucket.org] is built with Qt 5.0.2 MinGW, but should probably work with Qt 4. Download from here [bitbucket.org] . 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:
Well, you’re also suppose to add the following lines to your qmake project file:
…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:
The functionality provided is very very basic. If you wish to probe deeper to what this class can do, check the QxtCsvModel documentation [libqxt.bitbucket.org] .
CSV reader from QtSimplify(Read CSV Only)
http://qtsimplify.blogspot.com/2013/02/dealing-with-csv-files-easy-way.html
And that’s it! Feedback and discussions please go to http://forum.qt.io/viewthread/27167/