diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-10-26 06:25:01 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-27 21:03:14 +0000 |
commit | 62aab2b89ded0ca906606c2975358b1b6fc771f6 (patch) | |
tree | 5629d5cb7cee295a3644723c850948f969bbcf3c /examples/widgets/tools | |
parent | 34a74bbb410ce5fc212727cf331349281c4128a4 (diff) |
Fix treemodelcompleter example
All nodes in the view were at the top level due to a spurious trimmed()
call.
The condition in the indentation calculation was flipped, leading to a
segfault. Also, the input data does not contain tabs. Remove the
condition that checks for tabs altogether.
This amends commit 3fede6cb547b783377e833c9b269d4cecfe47e61.
Fixes: QTBUG-97727
Change-Id: Ic5068ead755c4dae5f0607724ac7704cce03227c
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
(cherry picked from commit 9beae46b599be011aab9f44efc92d49309b72da3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/widgets/tools')
-rw-r--r-- | examples/widgets/tools/treemodelcompleter/mainwindow.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp index 302ccc436c..91cdaee229 100644 --- a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp +++ b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp @@ -206,7 +206,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName) QRegularExpression re("^\\s+"); while (!file.atEnd()) { - const QString line = QString::fromUtf8(file.readLine()).trimmed(); + const QString line = QString::fromUtf8(file.readLine()); const QString trimmedLine = line.trimmed(); if (trimmedLine.isEmpty()) continue; @@ -218,7 +218,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName) level = 0; } else { const int capLen = match.capturedLength(); - level = line.startsWith(QLatin1Char('\t')) ? capLen / 4 : capLen; + level = capLen / 4; } if (level + 1 >= parents.size()) @@ -267,4 +267,3 @@ void MainWindow::updateContentsLabel(const QString &sep) { contentsLabel->setText(tr("Type path from model above with items at each level separated by a '%1'").arg(sep)); } - |