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. Cancel button on QProgressDialog is unresponsive - solved
Forum Updated to NodeBB v4.3 + New Features

Cancel button on QProgressDialog is unresponsive - solved

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 6.2k 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.
  • G Offline
    G Offline
    Gryffster
    wrote on last edited by
    #1

    Hi, I am using QProgressDialog to display the progress of a (potentially) long operation.

    @

    QProgressDialog cameraConnectProgressDialog("Connecting to Cameras", "Cancel", 0, 12, m_pParent );

    cameraConnectProgressDialog.setWindowModality(Qt::WindowModal);

    cameraConnectProgressDialog.setMinimumDuration(1);

    while ( someBoolean && ( cameraConnectProgressDialog.wasCanceled() == false ) )
    {
    // Do some potentially time-consuming processing

        ...
    
    
        // Let the user know how many fails/successes are occuring
    
        std :: ostringstream labelStream;
        labelStream << "Cameras Connected: " << displayedStreams - failedCameras << " Cameras Failed: " << failedCameras;
    
        QString progressLabel( labelStream.str().c_str() );
    
        cameraConnectProgressDialog.setLabelText( progressLabel );       // Update the label
        cameraConnectProgressDialog.setValue(displayedStreams);         // Update the current value on the progress bar
    
        QApplication::processEvents( QEventLoop::AllEvents );              // Process events (I know AllEvents is the default.)
    

    }
    @

    However, the Cancel button on the dialog is completely unresponsive. It doesn't respond to mouse press or release, and the dialog is not cancelled.

    What am I doing wrong? In all other respects, the dialog operates as expected.

    Thanks in advance

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goblincoding
      wrote on last edited by
      #2

      This might be a silly question, but did you connect the "Cancel" button's clicked signal to a relevant slot?

      http://www.goblincoding.com

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

        Hi,

        How long is your time consuming operation ? If it's really long, it will block the event loop so your dialog will be unresponsive.

        You might have to refactor your time consuming operation to allow the event loop to run from time to time.

        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
        • G Offline
          G Offline
          Gryffster
          wrote on last edited by
          #4

          Goblin - initially I did connect the button to the slot, but then I read this in the documentation:

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

          Which I interpreted as meaning that the default behaviour is that on cancel being activated, the wasCanceled property is set to true (which can then be accessed via the wasCanceled() accessor) and the dialog is dismissed. It was my understadning that overloading cancel() allows you to tailor the behaviour, but in my case, I'm solely concerned with whether or not the cancel button was activated.

          SGaist - the loop can take a few seconds, which is why I call QApplication::processEvents() each time around.

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

            In that case (IIRC), during the few seconds, the gui will be blocked. Can you split your task in smaller steps ?

            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
            • G Offline
              G Offline
              goblincoding
              wrote on last edited by
              #6

              [quote author="Gryffster" date="1366963766"]Goblin - initially I did connect the button to the slot, but then I read this in the documentation:

              "This signal is emitted when the cancel button is clicked. It is connected to the cancel() slot by default."[/quote]

              Oh, I see. Sorry for not being more useful! :)

              http://www.goblincoding.com

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Gryffster
                wrote on last edited by
                #7

                You are right, I've added extra calls to processEvents() during the processing loop, and the cancel button is activated. For whatever reason, that single call to processEvents at the end of the processing loop wasn't able to process events quickly enough (?)

                Thanks for your help!

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Gryffster
                  wrote on last edited by
                  #8

                  Goblin - no problems, thanks for finding the time to reply.

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

                    Great to see it works !

                    Don't forget to update the thread's title to solved so other forum users may know that a solution has been found :)

                    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
                    • G Offline
                      G Offline
                      Gryffster
                      wrote on last edited by
                      #10

                      Will do

                      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