1

I'm trying to compress data from a pugi::xml_document. This is what I tried :

template<class T> void save(const T &object, const QString &path)
{
    pugi::xml_document doc;
    object.exportXML(doc);

    std::ostringstream stream;
    doc.save(stream);

    QByteArray data = qCompress(stream.c_str(), 9);

    QFile outfile(path);
    outfile.write(data);
    outfile.close();
}

But it doesn't work because doc.save() takes a ostream and not a ostringstream. How can I get the tree formated to a string from the xml_document and compress it using qCompress?

Louis Etienne
  • 1,302
  • 3
  • 20
  • 37

1 Answers1

1

Be sure the no-stl define is commented in pugiconfig.hpp file:

// Uncomment this to disable STL
// #define PUGIXML_NO_STL 

The stringstream header include is required:

 #include <sstream>

That said, watch out: you're calling a non existing method c_str() directly on the std::ostringstream object, and not on its underlying string, returned by str() (and your compiler output should be something like: no member named 'c_str' in 'std::basic_ostringstream').

Your code should be like this:

QByteArray data = qCompress(stream.str().c_str(), 9);
p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35