PDA

View Full Version : How to save a Tablewidget in qt



namitha
15th June 2016, 12:44
Hi,

It will be a great help if anybody can assist me .
I have a Tablewidget which gets poulated with dynamic value each time we run it. In file menu i have save as and open entries. I want to save these data and open it as a tablewidget again.
Thanks in advance,
Namitha Pavithran

d_stranz
15th June 2016, 17:19
Easiest way is to save the contents as an ASCII CSV file. Create the CSV file, then for each row in the table, create a comma-separated row in the CSV file, one text field for each column. If any cell is empty, be sure to put a ",," empty field in the CSV file, otherwise you will end up with a mis-aligned table when you read it back in.

To read in, open the CSV file, then read each line into a QString. Use QString::split() to split the line into a QStringList of entries. Be sure to set the KeepEmptyParts flag. For line, add a row to the table, then for each entry in the string list, add a cell in that row.