c++ - How to use QProgressDialog along with QDomDocument save function -
to make long story short have program uses qdomdocument class create xml file , uses save() function save text stream object. its
qdomdocument somedoc; //create xml file, elements, etc. qfile io(filename); qtextstream out(&io); doc.save(out,4); io.close();
i want able show progress of save using qprogressdialog class, i'm having hard time figuring out. there way can incrementally check see if file through processing , update progress? suggestions? thanks.
firstly, thought can find answer in qt
source code, not simple, found easier solution, use tostring()
method , write usual file. example:
qstringlist = doc.tostring(4).split('\n');//4 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); (int = 0; < numfiles; i++) { progress->setvalue(i); if (progress->wascanceled()) break; stream << all.at(i) << '\n'; qthread::sleep(1);//remove these lines in release, example show process qcoreapplication::processevents(); } progress->setvalue(numfiles); file.close();
if want @ source code of qdomdocument::save()
, can find in
qt-everywhere-opensource-src-5.4.1.zip\qt-everywhere-opensource-src-5.4.1\qtbase\src\xml\dom