c++ - Progress bar for copying files -


i trying create progress bar file copy in qt. this close find, believe doesn't work because according qt class documentation:

unlike other qiodevice implementations, such qtcpsocket, qfile not emit abouttoclose(), byteswritten(), or readyread() signals. implementation detail means qfile not suitable reading , writing types of files, such device files on unix platforms.

how can this? don't know how implement own signals.

here code:

void replicator::anotbaandbfile(qdir source, qdir target) {     source.setfilter(qdir::files | qdir::nodotanddotdot | qdir::nosymlinks);     target.setfilter(qdir::files | qdir::nodotanddotdot | qdir::nosymlinks);      qdebug() << "scanning: " << source.path();      qstringlist sourcefilelist = source.entrylist();     qstringlist targetfilelist = target.entrylist();     (int acount = 0; acount < sourcefilelist.count(); acount++)     {         bool found = false;         (int bcount = 0; bcount < targetfilelist.count(); bcount++)             if (sourcefilelist.at(acount) == targetfilelist.at(bcount))                 found = true;         if (found == false)         {              sourcefile = new qfile(source.absolutepath()+"/"+sourcefilelist.at(acount));             targetfile = new qfile(target.absolutepath()+"/"+sourcefilelist.at(acount));             progressbar->setminimum(0);             progressbar->setmaximum(sourcefile->size());             written = 0;             connect(sourcefile,signal(byteswritten(qint64)),slot(onwrite(qint64)));             sourcefile->copy(targetfile->filename());             //qfile::copy(source.absolutepath()+"/"+sourcefilelist.at(acount), target.absolutepath()+"/"+sourcefilelist.at(acount));             qdebug() << source.absolutepath()+"/"+sourcefilelist.at(acount) << " " << target.absolutepath()+"/"+sourcefilelist.at(acount);         }     } } 

and

void replicator::onwrite(qint64 w) {     written += w;     progressbar->setvalue( written ); } 

new code modified above

if (found == false)         {             sourcefile = new qfile(source.absolutepath()+"/"+sourcefilelist.at(acount));             targetfile = new qfile(target.absolutepath()+"/"+sourcefilelist.at(acount));             progressbar->setminimum(0);             progressbar->setmaximum(sourcefile->size());             qbytearray buffer;             (int count = 0; !(buffer = sourcefile->read(1000000)).isempty(); count+=1000000)             {                 targetfile->write(buffer);                 progressbar->setvalue(count);             }             //targetfile->write(buffer);             //qfile::copy(source.absolutepath()+"/"+sourcefilelist.at(acount), target.absolutepath()+"/"+sourcefilelist.at(acount));             qdebug() << "copying " << sourcefile->filename() << " " << targetfile->filename();         } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -