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

    jsulmJ 1 Reply Last reply
    0
    • GilboonetG Gilboonet

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      GilboonetG 1 Reply Last reply
      0
      • jsulmJ jsulm

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

        GilboonetG Offline
        GilboonetG Offline
        Gilboonet
        wrote on 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

        jsulmJ 1 Reply Last reply
        0
        • GilboonetG Gilboonet

          @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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          GilboonetG 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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

            GilboonetG Offline
            GilboonetG Offline
            Gilboonet
            wrote on 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
            • GilboonetG Offline
              GilboonetG Offline
              Gilboonet
              wrote on last edited by Gilboonet
              #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.

              jsulmJ 1 Reply Last reply
              0
              • GilboonetG Gilboonet

                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.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on 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

                GilboonetG 1 Reply Last reply
                1
                • jsulmJ jsulm

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

                  GilboonetG Offline
                  GilboonetG Offline
                  Gilboonet
                  wrote on last edited by Gilboonet
                  #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
                  • GilboonetG Gilboonet has marked this topic as solved on
                  • GilboonetG Gilboonet referenced this topic on

                  • Login

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