Important: Please read the Qt Code of Conduct -

Qprocess with QprogressDialog or QprogressBar

  • Hi,
    Actually i am rnning a script as a qprocess on a clicked event signal. for this i need a status/progress bar how should i implement? in my search i found two different things one is QprogressDialog and QprogressBar.
    Please help this is my first iteraction to the progressBar.

  • @moyin let's see. QProgressBar is a widget so you'll need some other container (Dialog, Layout, MainWindow, etc.). QProgressDialog on the other hand is a 2in1 component: a dialog + progress bar.
    In any case, you need to figure out how to regularly update the progress of your QProcess (is it providing some progress value in standard output for instance, or just by guessing) and connecting the finished() signal of QProcess with a way to close the progress dialog

  • Thnks for rply,

    I'm trying implement QprogressDialog. by using below code but bit confused where should i run my scripts( where should i add the code to execute my Qprocess).

    class MyTask : public QObject
        explicit MyTask(QObject *parent = 0);
    public slots:
        void perform();
        void cancel();
        int steps;
        QProgressDialog *pd;
        QTimer *t;
    void MyDialog::on_mComputeBtn_clicked()
        myTask = new MyTask;
    MyTask::MyTask(QObject *parent) :
        QObject(parent), steps(0)
        pd = new QProgressDialog("Task in progress.", "Cancel", 0, 100000);
        connect(pd, SIGNAL(canceled()), this, SLOT(cancel()));
        t = new QTimer(this);
        connect(t, SIGNAL(timeout()), this, SLOT(perform()));
    void MyTask::perform()
        //... perform one percent of the operation
        if (steps > pd->maximum())
    void MyTask::cancel()
        //... cleanup

  • @moyin
    We don't understand: if you are running a sub-process, what is it that the progress bar is supposed to show? What does your code comment:

    //... perform one percent of the operation

    refer to? In the normal course of events, a parent process runs a sub-process, either waits for it to complete or does not as it pleases, and that's that. There is no "measuring of any progress".

    If perchance you mean one of:

    • The sub-process knows what its progress. It wants to update the progress bar in the parent. It can't do that (at least I don't know of any way).

    • The sub-process wants to signal/inform the parent process of its progress, so that the parent process can update the progress bar. Then we are getting into the available means of interprocess communication.

    What do you have in mind?

Log in to reply