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



  • 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]



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



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

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.