A
A
Anton Misyagin2020-04-13 13:14:27
Qt
Anton Misyagin, 2020-04-13 13:14:27

How to load text from file into TextArea by line break?

import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4


TextArea {
    id: editor

    text: "G0 X11 Y0"
    font.pixelSize: 10
    textFormat: TextEdit.RichText
    selectByMouse: true

    function loadTextFile(fileUrl){
        var xhr = new XMLHttpRequest;
        xhr.open("GET", fileUrl);
        xhr.onreadystatechange = function () {
            if(xhr.readyState === XMLHttpRequest.DONE){
                var response = xhr.responseText;
                console.log(response)
                editor.text = response
            }
        }
        xhr.send();
    }


    Component.onCompleted: {
        loadTextFile("../../res/gcode/example1.gcode")
    }
}


File content:
G0 (Rapid to start) X1 Y1
G0 X1 Y1 (Rapid to start; but don't forget the coolant)
M2 ; End of\n program.

The file is loaded, but for some reason everything is in one line, line breaks do not smell. Although in console.log(response)
the text is output to the console with line breaks. Help a beginner

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question