Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. How to implement svg output using QFileDialog.saveFileContent()
Servers for Qt installer are currently down

How to implement svg output using QFileDialog.saveFileContent()

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
save svg
7 Posts 1 Posters 867 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.
  • GilboonetG Offline
    GilboonetG Offline
    Gilboonet
    wrote on last edited by
    #1

    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.
    Screenshot_20230615_180734.png

    GilboonetG 1 Reply Last reply
    0
    • GilboonetG Offline
      GilboonetG Offline
      Gilboonet
      wrote on last edited by
      #6

      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

      Screenshot_20230618_115912.png

      1 Reply Last reply
      0
      • GilboonetG Gilboonet

        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.
        Screenshot_20230615_180734.png

        GilboonetG Offline
        GilboonetG Offline
        Gilboonet
        wrote on last edited by
        #2

        Apparently it is not something trivial, so as workaround I can try to build my svg using an external library as I did for the console version of my application.

        GilboonetG 1 Reply Last reply
        0
        • GilboonetG Gilboonet

          Apparently it is not something trivial, so as workaround I can try to build my svg using an external library as I did for the console version of my application.

          GilboonetG Offline
          GilboonetG Offline
          Gilboonet
          wrote on last edited by
          #3

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

          GilboonetG 1 Reply Last reply
          0
          • GilboonetG Gilboonet

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

            GilboonetG Offline
            GilboonetG Offline
            Gilboonet
            wrote on last edited by
            #4

            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.

            GilboonetG 1 Reply Last reply
            0
            • GilboonetG Gilboonet

              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.

              GilboonetG Offline
              GilboonetG Offline
              Gilboonet
              wrote on last edited by
              #5

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

              1 Reply Last reply
              0
              • GilboonetG Offline
                GilboonetG Offline
                Gilboonet
                wrote on last edited by
                #6

                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

                Screenshot_20230618_115912.png

                1 Reply Last reply
                0
                • GilboonetG Gilboonet has marked this topic as solved on
                • GilboonetG Gilboonet referenced this topic on
                • GilboonetG Offline
                  GilboonetG Offline
                  Gilboonet
                  wrote on last edited by
                  #7

                  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

                  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