How to save data(HTML) generated by QML/JS to an html file
Unsolved
QML and Qt Quick
-
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(/'\/index.php/)){ text = text.replace(/'\/index.php/, "http://en.wikitolearn.org/index.php"); text = text.replace(/&/,"&"); text = text.replace(/MathShowImage&/, "MathShowImage&") text = text.replace(/mode=mathml'/, "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(/&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() }
-
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 :