Important: Please read the Qt Code of Conduct -

ProgressBar for File Copy from source to destination on QT 5.9.2

  • Hi All,

    We are working on QT 5.9.2 for GUI (QtQucik Control Application 2)application, in that i want to work on progressbar , for my application there is a one button , when i clicked that button one more screen is appear in that it showing perentage of file copy(how many bytes file is copying), So Please give me any suggestions or any examples.


  • Moderators

    QFile does not report progress of file copying. So you need to either use a different library or copy file contents manually: one QFile to read from, another QFile to read to. That would give you a nice loop in which you can send percentage of completion to your progress bar easily (using some signal).

  • This post is deleted!

  • @sierdzio
    Please send me any examples on that

  • Moderators

    QFile in("input.txt");
    QFile out("output.txt");
    // I omit obvious stuff like checking if files exist, can be read/ written to, opening the files etc.
    for (int i  = 0; i < in.length(); ++i) {
        const QByteArray line = in.readLine();
        emit copyProgress(i, line);

    Something like this. For a more robust solution, use QDataStream and don't read lines but rather chunks of data. QFile documentation will help you with that.

  • @sierdzio
    Thanks sierdzio

    Will try this

  • Moderators

    this is of course untested and from the top of my head, no guarantee of compile succes or efficiency ;-)

     QProgressBar *progress = new QProgessBar();
    QtConcurrent::run(this, [=]{
    QFile src(SourceFile);
    QFile dst(DestinationFile);
    int chunkSize(256);
    if(src.exits() && ){
         QByteArray dataToCopy = src.readAll();
         if( {
              connect(this, myClass::setMaximum, progress, &QProgressBar::setMaximum);
              connect(this, myClass::setValue, progress, &QProgressBar::setValue);
             emit setMaximum(src.size() / chunkSize);
             int index(0);
                    QByteArray data =;
                    emit setValue(index);

Log in to reply