How to save data(HTML) generated by QML/JS to an html file



  • Hey , my qml file with the help of JS function generates HTML content . i want to save it in an HTML file .

    Is there any way to do this without using C++ ? if not how should i approach it ? .

    here is the code :

    import QtQuick 2.5
    import QtQuick.Window 2.2
    import QtWebEngine 1.1
    import QtWebKit 3.0
    
    
    Window {
        visible: true
        width: 600
        height: 400
    
        function parsing() {
            var http = new XMLHttpRequest();
            var json , parse , text ;
    
            http.onreadystatechange = function(){
                if(http.readyState == 4 && http.status == 200)
                { json = http.responseText;
    
                    parse = JSON.parse(json);
    
                    text = parse.parse.text["*"];
                    //console.log(text);
                     // <-- STRIP ME (o.O)
                    while(text.match(/&#39;\/index.php/)){
                    text = text.replace(/&#39;\/index.php/, "http://en.wikitolearn.org/index.php");
                    text = text.replace(/&amp;/,"&");
                    text = text.replace(/MathShowImage&amp;/, "MathShowImage&")
                    text = text.replace(/mode=mathml&#39;/, "mode=mathml\"");
                    text = text.replace(/<meta class="mwe-math-fallback-image-inline" aria-hidden="true" style="background-image: url\(/ ,"<img style=\"background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.838ex;height: 2.843ex; \" src=\"");
                    text = text.replace(/<meta class="mwe-math-fallback-image-display" aria-hidden="true" style="background-image: url\(/ ,"<img style=\"background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.838ex;height: 2.843ex; \" src=\"");
                    text = text.replace(/&amp;mode=mathml\"/ , "&mode=mathml>\"");
    
                    }
                    console.log(text); // after strip :p
                    webEngineView.loadHtml(text);
                }
            };
            http.open('GET','http://en.wikitolearn.org/api.php?action=parse&page=Linear%20Algebra/Sets&format=json');
            http.send();
        }
    
    
        WebView{
            id: webEngineView
            anchors.fill: parent
        }
    
        Component.onCompleted: parsing()
    }
    

  • Moderators

    @Qjay

    Is there any way to do this without using C++ ?

    No.

    if not how should i approach it ? .

    Create a class with required functions. Make them either Q_INVOKABLE or define them in public slots. Then to make it available to QML you can :



  • @p3c0

    Thanks for the idea . I was just wondering , can i do this with SQLite ? .

    I think i can use SQLite with JS .

    P.S. i have nothing against using C++ , it's just that i want to avoid or use it later in my application .


  • Moderators

    @Qjay Yes you can save the text but not an HTML file.
    May I know what is the reason to avoid using C++ ?



  • It's just that i had a thought i can write this whole application with QML/JS . SO i was trying to stick to it .

    But now it seems i will have to use C++ .


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.