Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to save data(HTML) generated by QML/JS to an html file
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qml + jsqt quickc++storage
5 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QjayQ Offline
    QjayQ Offline
    Qjay
    wrote on last edited by
    #1

    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()
    }
    
    p3c0P 1 Reply Last reply
    0
    • QjayQ Qjay

      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()
      }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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 :

      • Registering it as an Instantiable Object Type
      • Embed with context property

      157

      QjayQ 1 Reply Last reply
      1
      • p3c0P p3c0

        @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 :

        • Registering it as an Instantiable Object Type
        • Embed with context property
        QjayQ Offline
        QjayQ Offline
        Qjay
        wrote on last edited by
        #3

        @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 .

        p3c0P 1 Reply Last reply
        0
        • QjayQ Qjay

          @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 .

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by p3c0
          #4

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

          157

          1 Reply Last reply
          0
          • QjayQ Offline
            QjayQ Offline
            Qjay
            wrote on last edited by
            #5

            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++ .

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved