I would be inclined to adjust things a little and dispense with seek():
if (!in.atEnd()) {
str = in.readLine();
do {
if (str.section(" ",0,0) == "Heading") {
qDebug()<< "+" << str;
str = in.readLine();
while (!in.atEnd() && str.section(" ",0,0) == "") {
//process sub head line
qDebug()<< "*" << str;
str = in.readLine();
}
}
else
str = in.readLine();
} while (!in.atEnd());
}
}
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
if (!in.atEnd()) {
str = in.readLine();
do {
if (str.section(" ",0,0) == "Heading") {
qDebug()<< "+" << str;
str = in.readLine();
while (!in.atEnd() && str.section(" ",0,0) == "") {
//process sub head line
qDebug()<< "*" << str;
str = in.readLine();
}
}
else
str = in.readLine();
} while (!in.atEnd());
}
}
To copy to clipboard, switch view to plain text mode
You will need to check for correct behaviour with your actual data, but for this input:
Line1
Line2
Heading 1
sub head 1
sub head 2
sub head 3
Heading 2
sub head 1
sub head 2
Heading 3
sub head 1
...
Heading 4
Heading 5
more to ignore
Line1
Line2
Heading 1
sub head 1
sub head 2
sub head 3
Heading 2
sub head 1
sub head 2
Heading 3
sub head 1
...
Heading 4
Heading 5
more to ignore
To copy to clipboard, switch view to plain text mode
it gives:
+ "Heading 1"
* " sub head 1"
* " sub head 2"
* " sub head 3"
+ "Heading 2"
* " sub head 1"
* " sub head 2"
+ "Heading 3"
* " sub head 1"
+ "Heading 4"
+ "Heading 5"
+ "Heading 1"
* " sub head 1"
* " sub head 2"
* " sub head 3"
+ "Heading 2"
* " sub head 1"
* " sub head 2"
+ "Heading 3"
* " sub head 1"
+ "Heading 4"
+ "Heading 5"
To copy to clipboard, switch view to plain text mode
Bookmarks