Page 1 of 1

[SOLVED, kinda] How to QTextStream.readLine() when EOL is \r (=CR:CarriageReturn)

Posted: Thu Sep 19, 2024 6:57 am
by CVH
Andrew,

Received a pattern file that didn't work with QCAD.
More details in this topic

My custom tool Tile2Hatch also failed to cast the pattern dashes and or dots once.
And then I would expected a build in report or a failure on that 90% of the first bunch of definition lines where invalid.

After investigation the lines don't seem to end in \n or \r\n (NewLine or CarriageReturn + NewLine)
QTextStream.readLine() then reads the whole file with all occurring \r removed.

Searched online and this tells me that with Qt detecting End of Line is indeed hardcoded to \r\n and \n.

However, I can make it work.
Notepad++ is able to convert the EOL format of Windows (CR LF), Unix (LF) or Macintosh (CR).

Using or Windows, or Unix format the pattern is loaded.
I would have said "loaded perfectly" if the pattern was coded reasonable OK. :roll:

It is not ideal that users have to edit online sourced patterns, it is not a standalone case.

Thanks for any advice.
Regards,

Re: How to QTextStream.readLine() when EOL is \r (=CR:CarriageReturn)

Posted: Thu Sep 19, 2024 10:09 am
by John Hyslop
CVH wrote:
Thu Sep 19, 2024 6:57 am
Andrew,

Received a pattern file that didn't work with QCAD.
More details in this topic

My custom tool Tile2Hatch also failed to cast the pattern dashes and or dots once.
And then I would expected a build in report or a failure on that 90% of the first bunch of definition lines where invalid.

After investigation the lines don't seem to end in \n or \r\n (NewLine or CarriageReturn + NewLine)
QTextStream.readLine() then reads the whole file with all occurring \r removed.

Searched online and this tells me that with Qt detecting End of Line is indeed hardcoded to \r\n and \n.

However, I can make it work.
Notepad++ is able to convert the EOL format of Windows (CR LF), Unix (LF) or Macintosh (CR).

Using or Windows, or Unix format the pattern is loaded.
I would have said "loaded perfectly" if the pattern was coded reasonable OK. :roll:

It is not ideal that users have to edit online sourced patterns, it is not a standalone case.

Thanks for any advice.
Regards,
CVH

I think Andrew has enough on his plate without having to make allowances for "obviously" poorly coded patterns.😉


John

Re: How to QTextStream.readLine() when EOL is \r (=CR:CarriageReturn)

Posted: Thu Sep 19, 2024 11:00 am
by CVH
John,

It is the Macintosh EOL for text files that is the issue.
In itself it is not a false content.
For some reason Qt does not support that right out the box.

- - - - - -

If you are referring to 'poorly' meaning 'bad coded entries' in the given example pattern file, then I fully agree.
Try to set the origin of your hatch near (-6330, -1500).
That is how it should look like ... About. :lol:

The larged hurdle is the high cloning load in combination with the larger coordinate values.
Both do not seem to hinder other CAD applications, judging from the attached arguments.

Regards,
CVH

Re: How to QTextStream.readLine() when EOL is \r (=CR:CarriageReturn)

Posted: Thu Sep 19, 2024 3:29 pm
by CVH
It will remain a problem ...

At least I can catch it now and warn about a bad text data format:

Code: Select all

    file = new QFile(fileName);
    flags = new QIODevice.OpenMode(QIODevice.ReadOnly);
    if (file.open(flags)) {
        var content = file.readAll();
        var pos1 = content.indexOf("\r");
        var pos2 = content.indexOf("\n");
        if (pos1>0 && pos1+1 !== pos2) { 
            debugger;    // Warn user that EOL is probably CR
        }
    }
    file.close();
The solution is then a text editor, at least one knows what might be wrong.
CVH