summaryrefslogtreecommitdiffstats
path: root/examples/widgets/itemviews/frozencolumn/main.cpp
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@edeltech.ch>2017-11-10 21:36:27 +0100
committerSamuel Gaist <samuel.gaist@edeltech.ch>2018-03-29 19:12:03 +0000
commit1c4cae62771eb53987cc0684dcb662732a8509a9 (patch)
treecba516f8c871ecc51175cedf0eb5cb52b5c12d67 /examples/widgets/itemviews/frozencolumn/main.cpp
parent1d537071dea5668df991b0ccb82f14a5880b62c9 (diff)
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>
Diffstat (limited to 'examples/widgets/itemviews/frozencolumn/main.cpp')
-rw-r--r--examples/widgets/itemviews/frozencolumn/main.cpp9
1 files 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 <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){