Important: Please read the Qt Code of Conduct -

Qtextstream and Qfile

  • Hi guys,

    I'm using the above to create a bat file and dumping it over the network. I'm having a bit of a problem.
    when streaming text to the file it doesn't recognize << endl; or "/n".

    Also, i'm having a bit of a problem with / slashes.

    What is the best file class to use for batch files and how can i make the qtextstream to recognize new line symbols?


  • You have to use the backslash. It is '\n' for a new line.
    On which OS are you working. Apparently, you are working on a windows platform, since yu write a bat-file. How do you know, that the new line is not written?
    Some viewers do not recognize newline only.
    What problems do you have with '/'?

  • Thanks for your reply.

    Im working on windows, have realised my typo, have used the backslash with no joy.
    I know it hasnt read tge newline as the bat file has got all text on one line.
    Ive sorted the backslash problem, you just have to.double up with i forgor about.

  • Well, as I wrote seeing all text in one line does not necessarily mean that there is no newline in windows.
    Do you have a lister allowing to see it as hex?

    You may also try to write '\r' and '\n' at the line end.

    [Edit] Just saw this in the doc:
    [quote]Note: On Windows, all '\n' characters are written as '\r\n' if QTextStream's device or string is opened using the QIODevice::Text flag.
    So if you write on windows the translation is enforced in Qt. Do you open the file as a text file as recommended?

Log in to reply