From 011118521b4fa3072bb2b118ab624228778c29a0 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 26 Oct 2021 06:25:01 +0200 Subject: 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 (cherry picked from commit 9beae46b599be011aab9f44efc92d49309b72da3) Reviewed-by: Qt Cherry-pick Bot --- examples/widgets/tools/treemodelcompleter/mainwindow.cpp | 5 ++--- 1 file 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)); } - -- cgit v1.2.3