Firstly, I thought that we could find the answer in the Qt source code, but it was not so simple, so I found an easier solution, just use the toString() method and write it as a regular file. For instance:
QStringList all = doc.toString(4).split('\n');//4 is intent int numFiles = all.size(); QProgressDialog *progress = new QProgressDialog("Copying files...", "Abort Copy", 0, numFiles, this); progress->setWindowModality(Qt::WindowModal); QFile file("path"); file.open(QIODevice::WriteOnly); progress->show(); QTextStream stream(&file); for (int i = 0; i < numFiles; i++) { progress->setValue(i); if (progress->wasCanceled()) break; stream << all.at(i) << '\n'; QThread::sleep(1);//remove these lines in release, it is just example to show the process QCoreApplication::processEvents(); } progress->setValue(numFiles); file.close();
If you want to see the source code of QDomDocument::save() , you can find it in
qt-everywhere-opensource-src-5.4.1.zip \ Qt-everywhere open-source -src-5.4.1 \ qtbase \ SRC \ XML \ home
or just on github.
source share