PDA

View Full Version : Unable to get QSvgGenerator to write to a device



danlyke
15th December 2017, 01:48
I am trying to get the output of QSvgGenerator into a string for use in-line in HTML. I can use the .setFileName(...) method, and get output as a file, but .setOutputDevice(&qbuffer) doesn't add anything to the qbuffer (and I can use qbuffer.write(...); to write strings into the buffer before and after the scene.render( &painter ); rendering operation gets called on the QSvgGenerator.

I've attached a complete stand-alone command-line app (.cpp, .h and .pro) to demonstrate the problem, though I'm experiencing this in a full GUI app. Running this application with no arguments should dump an SVG containing a rectangle to the console. Running the application with an argument writes the SVG file to the first argument (this works).

ChrisW67
17th December 2017, 07:04
You need to finish the painting before trying to read the buffer (or it will not be finished until the painter is destroyed, which is after you read).


QPainter painter( &svgGenerator );
scene.render( &painter );
painter.end();