Results 1 to 5 of 5

Thread: SVG to QByteArray

  1. #1
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default SVG to QByteArray

    Hello dear programmers.

    Have searched everywhere on the net for this information but could not find something that helped me solve my problem.

    I want to convert an SVG file to an QByteArray. This I want to do because I want to save that SVG image in QByteArray::toBase64() format. And since there in QSvgRenderer constructor there is a possibility to load from a QByteArray I would think this is possible but me not being able to solve this.

    Appreciate all the help I can get.

  2. #2
    Join Date
    May 2011
    Posts
    240
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: SVG to QByteArray

    The way I see it, forget that the file is an SVG file; don't think of the problem as conversion, but just as reading a file into a QByteArray. Just create a QBytearray and read the file into it, not caring what the contents are.

  3. The following user says thank you to mvuori for this useful post:

    meazza (5th July 2011)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,552
    Thanks
    13
    Thanked 1,579 Times in 1,508 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SVG to QByteArray

    I am not sure why you would want to Base64 encode an SVG file: it is already text after all.
    Qt Code:
    1. QFile input("myfile.svg");
    2. QFile output("myfile.b64");
    3. if (input.open(QIODevice::ReadOnly) && output.open(QIODevice::WriteOnly)) {
    4. QByteArray ba = input.readAll();
    5. input.close();
    6. output.write(ba.toBase64());
    7. output.close();
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    meazza (5th July 2011)

  6. #4
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SVG to QByteArray

    I am not sure why you would want to Base64 encode an SVG file: it is already text after all.
    Well I have an application where you can load different types of images (svg, pbg and jpg) and I am saving PNG and JPG base64 encoded to an xml document so thought might aswell do that to the SVG images aswell.

    Am I losing something when I do this or?

  7. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,552
    Thanks
    13
    Thanked 1,579 Times in 1,508 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SVG to QByteArray

    If you are doing this to store an arbitrary binary blob inside another text format then this is a reasonable way to do it. You should not be losing anything except a little bit of disk space for the large Base64 version.

Similar Threads

  1. Replies: 1
    Last Post: 22nd June 2011, 08:12
  2. XoR on hex/QByteArray
    By meena in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2010, 15:41
  3. Replies: 9
    Last Post: 25th July 2009, 13:27
  4. QByteArray
    By gyre in forum Newbie
    Replies: 4
    Last Post: 9th October 2007, 18:30
  5. QByteArray in Qt3
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 06:16

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.