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. Using QSvgGenerator with WebAssembly
Forum Updated to NodeBB v4.3 + New Features

Using QSvgGenerator with WebAssembly

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
8 Posts 2 Posters 728 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 30 Nov 2024, 22:21 last edited by Gilboonet
    #1

    Hello, my application goal is to generate a svg file. For my first version, I was unable to use QSvgGenerator with WebAssembly simply because I didn't find how to do the following :

    To write an SVG file, you first need to configure the output 
    by setting the fileName or outputDevice properties.
    It is usually necessary to specify the size of the drawing 
    by setting the size property, and in some cases where 
    the drawing will be included in another, 
    the viewBox property also needs to be set.
    

    I found a workaround that worked very well using an external library, but I'm hoping that there is a way to use QSvgGenerator and configure the output that works with WebAssembly.

    J 1 Reply Last reply 2 Dec 2024, 06:41
    0
    • G Gilboonet
      30 Nov 2024, 22:21

      Hello, my application goal is to generate a svg file. For my first version, I was unable to use QSvgGenerator with WebAssembly simply because I didn't find how to do the following :

      To write an SVG file, you first need to configure the output 
      by setting the fileName or outputDevice properties.
      It is usually necessary to specify the size of the drawing 
      by setting the size property, and in some cases where 
      the drawing will be included in another, 
      the viewBox property also needs to be set.
      

      I found a workaround that worked very well using an external library, but I'm hoping that there is a way to use QSvgGenerator and configure the output that works with WebAssembly.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 2 Dec 2024, 06:41 last edited by
      #2

      @Gilboonet What is the problem?
      https://doc.qt.io/qt-6/qsvggenerator.html even shows some code.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply 2 Dec 2024, 07:43
      0
      • J jsulm
        2 Dec 2024, 06:41

        @Gilboonet What is the problem?
        https://doc.qt.io/qt-6/qsvggenerator.html even shows some code.

        G Offline
        G Offline
        Gilboonet
        wrote on 2 Dec 2024, 07:43 last edited by
        #3

        @jsulm For the basic usage of QSvgGenerator, there's no problem, on Desktop it works fine, but I didn't find how to make it output using WebAssembly as there are restrictions. I made a post explaining my problem here (more than 1 year ago, so I'm hoping that now someone could help even if it seems that not many people uses WebAssembly) here

        J 1 Reply Last reply 2 Dec 2024, 07:49
        0
        • G Gilboonet
          2 Dec 2024, 07:43

          @jsulm For the basic usage of QSvgGenerator, there's no problem, on Desktop it works fine, but I didn't find how to make it output using WebAssembly as there are restrictions. I made a post explaining my problem here (more than 1 year ago, so I'm hoping that now someone could help even if it seems that not many people uses WebAssembly) here

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 2 Dec 2024, 07:49 last edited by
          #4

          @Gilboonet I'm still not sure what exactly the problem is.
          You can't write in a file?
          https://doc.qt.io/qt-6/wasm.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply 2 Dec 2024, 08:00
          0
          • J jsulm
            2 Dec 2024, 07:49

            @Gilboonet I'm still not sure what exactly the problem is.
            You can't write in a file?
            https://doc.qt.io/qt-6/wasm.html

            G Offline
            G Offline
            Gilboonet
            wrote on 2 Dec 2024, 08:00 last edited by
            #5

            @jsulm I'm using WebAssembly since the beginning of this project, about 2 years, and there are still lots of topics where there is not enough information. Here, the problem is that the same code that works on Desktop and saves the file, does nothing and remain silent on WebAssembly. It might be the mechanism that is intended to fire the writing process of the SVG file, with

            painter.end;
            

            that should be started using another way, but I still didn't find it.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Gilboonet
              wrote on 2 Dec 2024, 08:13 last edited by Gilboonet 12 Feb 2024, 08:14
              #6

              With WebAssembly, there's a dedicated function to use with QFileDialog so that you can write a file, I use that function successfully to save my project data file, but what exactly I didn't manage to do is have the svg content of QSvgGenerator transferred to a QByteArray that the function need to save it. For the moment I'm doing this all by an external class, just like I'm doing for the 3d part.

              J 1 Reply Last reply 2 Dec 2024, 08:21
              0
              • G Gilboonet
                2 Dec 2024, 08:13

                With WebAssembly, there's a dedicated function to use with QFileDialog so that you can write a file, I use that function successfully to save my project data file, but what exactly I didn't manage to do is have the svg content of QSvgGenerator transferred to a QByteArray that the function need to save it. For the moment I'm doing this all by an external class, just like I'm doing for the 3d part.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 2 Dec 2024, 08:21 last edited by
                #7

                @Gilboonet You can set a https://doc.qt.io/qt-6/qbuffer.html via https://doc.qt.io/qt-6/qsvggenerator.html#outputDevice-prop and after painting call https://doc.qt.io/qt-6/qbuffer.html#data to get the QByteArray.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                G 1 Reply Last reply 2 Dec 2024, 08:33
                1
                • J jsulm
                  2 Dec 2024, 08:21

                  @Gilboonet You can set a https://doc.qt.io/qt-6/qbuffer.html via https://doc.qt.io/qt-6/qsvggenerator.html#outputDevice-prop and after painting call https://doc.qt.io/qt-6/qbuffer.html#data to get the QByteArray.

                  G Offline
                  G Offline
                  Gilboonet
                  wrote on 2 Dec 2024, 08:33 last edited by Gilboonet 12 Feb 2024, 10:45
                  #8

                  @jsulm Thank you, I try that ASAP.

                  It works fine either on Desktop and Wasm. Now I need to plug my data.

                  void MainWindow::exporter()
                  {
                      QSvgGenerator SG;
                      SG.setSize(QSize(200, 200));
                      SG.setViewBox(QRect(0, 0, 200, 200));
                      SG.setTitle(tr("SVG Generator Example Drawing"));
                      SG.setDescription(tr("An SVG drawing created by the SVG Generator "
                                                  "Example provided with Qt."));
                  
                      QPainter painter;
                      QBuffer buffer;
                      SG.setOutputDevice(&buffer);
                  
                      painter.begin(&SG);
                  
                  
                      painter.end();
                  
                      QFileDialog::saveFileContent(buffer.data(), "myExport.svg");
                  }
                  
                  1 Reply Last reply
                  0
                  • G Gilboonet has marked this topic as solved on 2 Dec 2024, 10:45
                  • G Gilboonet referenced this topic on 2 Dec 2024, 12:06

                  4/8

                  2 Dec 2024, 07:49

                  • Login

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