Improve the Frozen Column example

This patch updates the frozen column example to use QTextStream which
offers a more convenient way to read text files and also takes care of
converting the 8-bit data stored on disk into a 16-bit Unicode QString.

Change-Id: Ifd03903ac14b48b026d8770cda726f8ed2756ab4
Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com>
This commit is contained in:
Samuel Gaist 2017-11-10 21:36:27 +01:00
parent 1d537071de
commit 1c4cae6277

View File

@ -51,6 +51,7 @@
#include <QApplication>
#include <QStandardItemModel>
#include <QFile>
#include <QTextStream>
#include "freezetablewidget.h"
@ -63,14 +64,16 @@ int main(int argc, char* argv[])
QFile file(":/grades.txt");
if (file.open(QFile::ReadOnly)) {
QString line = file.readLine(200);
QTextStream stream(&file);
QString line = stream.readLine();
QStringList list = line.simplified().split(',');
model->setHorizontalHeaderLabels(list);
int row = 0;
QStandardItem *newItem = 0;
while (file.canReadLine()) {
line = file.readLine(200);
while (!stream.atEnd()) {
line = stream.readLine();
if (!line.startsWith('#') && line.contains(',')) {
list = line.simplified().split(',');
for (int col = 0; col < list.length(); ++col){