[SOLVED] Displaying Table from plain text file using QTableView
I am retrieving information in the form of plain text files and i want to just display these tables in a neat way – which of the above is a better way. Any other suggestions ?
QTableView displays a model as tabel. QDataWidgetMapper ampps the data of a model to a bunch of widgets.
So displaying data in a table is a typical task of QTableView and a QAbstractTableModel [doc.qt.nokia.com] derived class. But you have to parse your text and create the model. See here for an example inside Qt documentation [doc.qt.nokia.com]
Thanks for all your suggestions. I decided to use QTableView.
Following a previous post http://www.qtcentre.org/threads/17377-QTableView-memory-consumption , i have come up with the following code :
- Widget::Widget(QWidget *parent) :
- int Max_num_of_Columns(8);
- int Max_Number_of_Lines(0);
- QFile file("/path/to/txt/file");
- qDebug() << "Error opening file";
- QTextStream InputDataFile(&file);
- while (!InputDataFile.atEnd())
- QString line = InputDataFile.readLine();
- QStringList fields = line.split(" ");
- if (fields.size() == Max_num_of_Columns)
- for (int column=0; column< Max_num_of_Columns; column++)
- mytablemodel->setItem(Max_Number_of_Lines, column, item);
- Max_Number_of_Lines++ ;
I am unable to follow the model/view very well. Please help me figure out how to make this work. Just read a plain text file and display it in a tabular fashion.
Thanks a lot.