Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    3
    2789
    Loading More Posts
    • 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
      mr_gui last edited by

      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 Reply Quote 0
      • F
        Felix last edited by

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

        1 Reply Last reply Reply Quote 0
        • M
          mr_gui last edited by

          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 Reply Quote 0
          • First post
            Last post