From 1c4cae62771eb53987cc0684dcb662732a8509a9 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Fri, 10 Nov 2017 21:36:27 +0100 Subject: [PATCH] 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 --- examples/widgets/itemviews/frozencolumn/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/widgets/itemviews/frozencolumn/main.cpp b/examples/widgets/itemviews/frozencolumn/main.cpp index 5a4d3e0f42..6f2b4a8d71 100644 --- a/examples/widgets/itemviews/frozencolumn/main.cpp +++ b/examples/widgets/itemviews/frozencolumn/main.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #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){