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()
Forum Updated to NodeBB v4.3 + New Features

How to implement svg output using QFileDialog.saveFileContent()

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
save svg
7 Posts 1 Posters 771 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.
  • G Offline
    G Offline
    Gilboonet
    wrote on 15 Jun 2023, 16:48 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

    G 1 Reply Last reply 15 Jun 2023, 19:05
    0
    • G Offline
      G Offline
      Gilboonet
      wrote on 18 Jun 2023, 10:26 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
      • G Gilboonet
        15 Jun 2023, 16:48

        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

        G Offline
        G Offline
        Gilboonet
        wrote on 15 Jun 2023, 19:05 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.

        G 1 Reply Last reply 16 Jun 2023, 07:37
        0
        • G Gilboonet
          15 Jun 2023, 19:05

          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.

          G Offline
          G Offline
          Gilboonet
          wrote on 16 Jun 2023, 07:37 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.

          G 1 Reply Last reply 16 Jun 2023, 14:49
          0
          • G Gilboonet
            16 Jun 2023, 07:37

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

            G Offline
            G Offline
            Gilboonet
            wrote on 16 Jun 2023, 14:49 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.

            G 1 Reply Last reply 16 Jun 2023, 20:33
            0
            • G Gilboonet
              16 Jun 2023, 14:49

              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.

              G Offline
              G Offline
              Gilboonet
              wrote on 16 Jun 2023, 20:33 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
              • G Offline
                G Offline
                Gilboonet
                wrote on 18 Jun 2023, 10:26 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
                • G Gilboonet has marked this topic as solved on 18 Jun 2023, 10:26
                • G Gilboonet referenced this topic on 2 Dec 2024, 07:43
                • G Offline
                  G Offline
                  Gilboonet
                  wrote on 2 Dec 2024, 12:06 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

                  1/7

                  15 Jun 2023, 16:48

                  • Login

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