Parsing CSV File
-
wrote on 10 Jul 2020, 21:59 last edited by
Hello,
I am looking for a way to parse CSV file without having to reinvent the wheel. I found the libqxt library, but it seems that is not maintained anymore and developers even recommend not using it due to the changes in recent Qt versions.
Is there any way to do it ?
Best
-
Hi
For simple CSV, Qt QString's split function makes it very easy.
https://doc.qt.io/qt-5/qstring.html#splitThere is
https://github.com/iamantony/qtcsv -
Hello,
I am looking for a way to parse CSV file without having to reinvent the wheel. I found the libqxt library, but it seems that is not maintained anymore and developers even recommend not using it due to the changes in recent Qt versions.
Is there any way to do it ?
Best
wrote on 16 Jul 2020, 09:28 last edited by@DSpider And if the CSV text is more complex, for example containing binary data or embedded line feeds, there is this very nice little library which can do it: https://github.com/rgamble/libcsv
However, it is written in C (not C++) and, although the field separator and the quote character can be freely chosen, requires that they are 8-bit characters. Usually, it is enough to ensure that the input is in UTF-8 encoding or some other 8-bit character set.
The data is read sequentially from beginning to end, byte by byte. To use it, you need to write two callback functions which are called whenever a field is detected, and at the end of a line. I like it because I can validate the input data field-by-field.
3/3