Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]QXmlStreamWriter "setDevice(...)" not working
QtWS25 Last Chance

[solved]QXmlStreamWriter "setDevice(...)" not working

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.9k 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.
  • M Offline
    M Offline
    mr_gui
    wrote on last edited by
    #1

    I have a problem with the setDevice function of QXmlStreamWriter.

    If I do (like it is posted in the QT doc):
    @
    QByteArray ba;
    QBuffer buffer( &ba );
    QXmlStreamWriter xml_writer;
    xml_writer.setDevice( &buffer );

    xml_writer.writeStartDocument();
    xml_writer.writeDTD("<!DOCTYPE xbel>");
    xml_writer.writeStartElement("Element");
    xml_writer.writeAttribute("version", "1.0");
    xml_writer.writeEndDocument();
    QString xml_file( ba );
    @

    I get an empty xml_file string (also the bytearray ba is empty).

    If I do:

    @
    QByteArray ba;
    //QBuffer buffer( &ba );
    QXmlStreamWriter xml_writer( &ba );
    //xml_writer.setDevice( &buffer );
    ....
    @

    I get the xml message in the bytearray and string.

    What do I do wrong?

    [edit: mark up code, Tobias Hunger]

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Felix
      wrote on last edited by
      #2

      i think you have to call buffer.open(QIODevice::WriteOnly). Have you tried this already?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mr_gui
        wrote on last edited by
        #3

        Argh, of course that's the problem!! Thank you!

        This is what happens if you write test routines in existing projects...

        1 Reply Last reply
        0

        • Login

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