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 15:33:38 +0000 |
commit | 011118521b4fa3072bb2b118ab624228778c29a0 (patch) | |
tree | b34ee9dd3cc1a2ed9c9628ca602fe13ceb6583c3 /examples | |
parent | f1c6d469ca52f4e9082d7bc55b1dbf19addba3c0 (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')
-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 44c5b1312a..0c6bb66103 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)); } - |