How to implement svg output using QFileDialog.saveFileContent()
-
Hello, I tried Web Assembly of my C++ Application and I managed to adapt it to use QFileDialog.getFileContent() to open files, but I don't understand how to use the same mechanism using QFileDialog.saveFileContent() to save the graphic content I created to svg. I'm using QPainter and QSvgGenerator for that and it saves with the filename I set with QSvgGenerator object setFileName() when I call QPainter object end(). Is it possible to get the svg data and put it into a QByteArray ?
here's my application running into the browser, Web Assembly is really impressive.
-
Well I have now a svg output that is exactly what I wanted, and as it work for both Desktop and Web Assembly version, I remove QT svg support. I used svg paths of Hershey font that and added a function that uses them to create a path. The overall size of the path is smaller like that because each character is a single line path not an outline.
The project source is here : https://github.com/gilboonet/Deplieur-CPP
The Web Assembly version can be tested here : https://gilboonet.github.io/deplieur/UI1.html -
@Gilboonet What I'm trying to do is changing the "export to svg" process of my QT C++ Application that calls
- QFileDialog.getSaveFileName() to get the file name
- redraws the application QGraphicsView that also uses a QPainter and a QSvgGenerator so that the needed graphical elements (paths and texts) are created and save to the given file when I call QPainter object end().
I'm now using
QByteArray a("svgData"); QFileDialog::saveFileContent(a, "export.svg");
And what I am looking for is a way to put the svg data into a QByteArray so that I can save it to file from the webAssembly application.
-
I tested the principle it works, I am able to build a svg object (I'm using this library https://vincentlaucsb.github.io/svg/index.html) and to store its contents (as string) into my main data object as QByteArray that I can pass to QFileDialog::saveFileContent(). I'm wondering whether QSvgRenderer could retrieve this same string content from the QSvgGenerator object, but I didn't see anything that made me think it does.
-
@Gilboonet Well, it works and now my application is almost ready as a web application, I only need to redesign the way I save a project to only use one file and it will fully work. There's only one drawback : I wasn't able to transform the texts elements to path as it was possible with QPainterPath. But anyway I am very happy, for a first C++ and first QT application I didn't expect to be able to do all that.
-
Well I have now a svg output that is exactly what I wanted, and as it work for both Desktop and Web Assembly version, I remove QT svg support. I used svg paths of Hershey font that and added a function that uses them to create a path. The overall size of the path is smaller like that because each character is a single line path not an outline.
The project source is here : https://github.com/gilboonet/Deplieur-CPP
The Web Assembly version can be tested here : https://gilboonet.github.io/deplieur/UI1.html -
-
-
on 2 dec. 2024, I asked that question again and someone gave me an answer, see https://forum.qt.io/topic/159970/using-qsvggenerator-with-webassembly