[SOLVED] Displaying Table from plain text file using QTableView
Hi,
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 ?
5 replies
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 :
- {
- mytablemodel->setRowCount(0);
- int Max_num_of_Columns(8);
- int Max_Number_of_Lines(0);
- mytablemodel->setColumnCount(Max_num_of_Columns);
- qDebug() << "Error opening file";
- while (!InputDataFile.atEnd())
- {
- 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++ ;
- }
- }
- file.close();
- mytable->setModel(mytablemodel);
- mytable->show();
- }
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.
You must log in to post a reply. Not a member yet? Register here!




