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. Can't Cancel Progress Dialog.
QtWS25 Last Chance

Can't Cancel Progress Dialog.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt4c++progress barsignalcancel
12 Posts 3 Posters 5.7k Views
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Is it a typo here or do you really have signal in place of SIGNAL in your code ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DougyDrumz
      wrote on last edited by
      #3

      It's a Typo.

      Dougy Drumz

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Can you show the complete code where you are using that dialog ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DougyDrumz
          wrote on last edited by
          #5

          It comes from a separate network. Let see if I can get it off.

          Dougy Drumz

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DougyDrumz
            wrote on last edited by
            #6

            myProgressTimer = new QTimer(this);

            ...

            connect(myProgressDialog, signal(canceled()), this, SLOT(cancelProgress));
            connect(myProgressTimer, signal(timeout()), this, SLOT(updateProgress));

            ...
            myProgressTimer ->setRange(0, 100);
            myProgressTimer ->start(1000);

            ...

            cancelProgress
            (
            myProgressDialog->cancel();
            myProgressTimer->stop();
            myProgressStep = 0;
            )

            updateProgress()
            (
            if (myProgressDialog->wasCanceled())
            (
            #Do Something.
            )
            myProgressDialog-<setValue(myProgressStep++);

            if (myProgressStep > myProgressDialog->maximum())
            {
                myProgressDialog->cancel(); //This Works!
                
                if (myProgressTimer)
               {
                   myProgressTimer ->stop(); //This Works!          
               }
            
               myProgressStep = 0;
            

            }

            Dougy Drumz

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mostefa
              wrote on last edited by mostefa
              #7

              Hi @DougyDrumz

              After testing your code cancelProgress slot is called when cancel button is clicked:

              But you are telling :

              If I press the cancel button or the X (Close) button,

              AFAIK canceled signal of progressDialog is just emitted when cancel button is clicked, not when X (Close) button,

              see the doc:

              http://doc.qt.io/qt-5/qprogressdialog.html#canceled

              This signal is emitted when the cancel button is clicked. It is connected to the cancel() slot by default.

              Here is the code that work when cancel button is clicked:

              MainWindow.h

              #ifndef MAINWINDOW_H
              #define MAINWINDOW_H
              
              #include <QMainWindow>
              #include <QProgressDialog>
              
              namespace Ui {
              class MainWindow;
              }
              
              class MainWindow : public QMainWindow
              {
                  Q_OBJECT
              
              public:
                  explicit MainWindow(QWidget *parent = 0);
                  ~MainWindow();
              
              private slots:
                  void cancelProgress();
                  void updateProgress();
              
              private:
                  Ui::MainWindow *ui;
                  QProgressDialog* myProgressDialog;
                  QTimer* myProgressTimer;
                  int myProgressStep;
              };
              
              #endif // MAINWINDOW_H
              

              MainWindow.cpp

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              
              #include <QTimer>
              #include <QProgressDialog>
              
              #include <QDebug>
              MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
              
              
              
                  myProgressTimer = new QTimer(this);
              
                  myProgressDialog= new QProgressDialog(this);
              
                  ui->verticalLayout->addWidget(myProgressDialog);
              
                  connect(myProgressDialog, SIGNAL(canceled()), this, SLOT(cancelProgress()));
                  connect(myProgressTimer, SIGNAL(timeout()), this, SLOT(updateProgress()));
              
                  myProgressTimer->start(1000);
                  myProgressStep = 0;
              }
              
              MainWindow::~MainWindow()
              {
                  delete ui;
              }
              
              void MainWindow::cancelProgress()
              {
                  qDebug() << myProgressDialog->wasCanceled() << "<==canceled?";
                  qDebug() << Q_FUNC_INFO << "i am cancelled";
                  myProgressDialog->cancel();
                  myProgressTimer->stop();
              }
              
              void MainWindow::updateProgress()
              {
                  myProgressDialog->setValue(myProgressStep++);
                  if (myProgressDialog->wasCanceled())
                  {
                     // do something
                  }
              }
              

              And here is the ouput code when cancel button is clicked:

              true <==canceled?
              void MainWindow::cancelProgress() i am cancelled

              Hope this can help !

              1 Reply Last reply
              2
              • D Offline
                D Offline
                DougyDrumz
                wrote on last edited by
                #8

                cancelProgress doesn't get called for me, neither when hitting the Cancel button nor the Close button.

                Dougy Drumz

                M 1 Reply Last reply
                0
                • D DougyDrumz

                  cancelProgress doesn't get called for me, neither when hitting the Cancel button nor the Close button.

                  M Offline
                  M Offline
                  mostefa
                  wrote on last edited by mostefa
                  #9

                  @DougyDrumz said in Can't Cancel Progress Dialog.:

                  cancelProgress doesn't get called for me, neither when hitting the Cancel button nor the Close button.

                  Have you tried with the code that i shared on the previous post?

                  You might have error on syntax of your connect

                  connect(myProgressDialog, signal(canceled()), this, SLOT(cancelProgress));
                  

                  Try with my code , i know that it work 100%

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DougyDrumz
                    wrote on last edited by
                    #10

                    I'm doing the same thing you're doing (re the ProgressDialog). There is no syntax error. The interesting thing is that when I push the Cancel Button, it does pop down and pop right back up. How does it do this if cancelProgress is not called. What is it calling? Also interesting is that the close (X) buitton is pressed, it does cancel, buit only on the second attempt. I changed the QTimer start from 1000 to 100 to 1 and it didn't change anything. What the heck is going on here? I have another qtimer to update a clock. Could this be interfering with the Progress QTimer?

                    Dougy Drumz

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DougyDrumz
                      wrote on last edited by
                      #11

                      OK. I found it. I was being dumb! I have two flavors of Progress Dialogs. One is inside an App, and the other is standalone, meant to be called form a script. I was looking at the one in the App when I should have been looking at the other one. The standalone one doesn't have have a cancel slot.

                      Dougy Drumz

                      M 1 Reply Last reply
                      0
                      • D DougyDrumz

                        OK. I found it. I was being dumb! I have two flavors of Progress Dialogs. One is inside an App, and the other is standalone, meant to be called form a script. I was looking at the one in the App when I should have been looking at the other one. The standalone one doesn't have have a cancel slot.

                        M Offline
                        M Offline
                        mostefa
                        wrote on last edited by
                        #12

                        @DougyDrumz said in Can't Cancel Progress Dialog.:

                        OK. I found it. I was being dumb! I have two flavors of Progress Dialogs. One is inside an App, and the other is standalone, meant to be called form a script. I was looking at the one in the App when I should have been looking at the other one. The standalone one doesn't have have a cancel slot.

                        Good !

                        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