Results 1 to 2 of 2

Thread: Unable to get QSvgGenerator to write to a device

  1. #1
    Join Date
    Dec 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Unable to get QSvgGenerator to write to a device

    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).
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Unable to get QSvgGenerator to write to a device

    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).
    Qt Code:
    1. QPainter painter( &svgGenerator );
    2. scene.render( &painter );
    3. painter.end();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 24th October 2016, 21:15
  2. Unable to write in QTextEdit
    By dikku in forum Newbie
    Replies: 4
    Last Post: 30th December 2015, 08:53
  3. Replies: 5
    Last Post: 17th April 2015, 07:09
  4. Circular reference ... Unable to write forwarding
    By tonnot in forum General Programming
    Replies: 6
    Last Post: 27th June 2011, 11:26
  5. Unable to write to file QFile
    By cuter in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2009, 11:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.