Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qprocess with QprogressDialog or QprogressBar
Qt 6.11 is out! See what's new in the release blog

Qprocess with QprogressDialog or QprogressBar

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moyin
    wrote on last edited by
    #1

    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.

    Pablo J. RoginaP 1 Reply Last reply
    0
    • M moyin

      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.

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @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

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • M Offline
        M Offline
        moyin
        wrote on last edited by
        #3

        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
        {
            Q_OBJECT
        public:
            explicit MyTask(QObject *parent = 0);
        
        signals:
        
        public slots:
            void perform();
            void cancel();
        private:
            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()));
            t->start(0);
        }
        
        void MyTask::perform()
        {
            pd->setValue(steps);
            //... perform one percent of the operation
            steps++;
            if (steps > pd->maximum())
                t->stop();
        }
        
        void MyTask::cancel()
        {
            t->stop();
            //... cleanup
        }
        
        JonBJ 1 Reply Last reply
        0
        • M moyin

          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
          {
              Q_OBJECT
          public:
              explicit MyTask(QObject *parent = 0);
          
          signals:
          
          public slots:
              void perform();
              void cancel();
          private:
              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()));
              t->start(0);
          }
          
          void MyTask::perform()
          {
              pd->setValue(steps);
              //... perform one percent of the operation
              steps++;
              if (steps > pd->maximum())
                  t->stop();
          }
          
          void MyTask::cancel()
          {
              t->stop();
              //... cleanup
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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?

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved