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. Problem with a modal dialog connecting with a process

Problem with a modal dialog connecting with a process

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 572 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.
  • M Offline
    M Offline
    medihech
    wrote on last edited by
    #1

    Hi, everyone.

    I have created a dialog where a button's clicked method is connected with a slot to stop the process.
    When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.

    It seems I have to run the process in a new thread, is it?
    Could I run the dialog in a new thread?

    Thank in advance.

    Christian EhrlicherC 1 Reply Last reply
    0
    • M medihech

      Hi, everyone.

      I have created a dialog where a button's clicked method is connected with a slot to stop the process.
      When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.

      It seems I have to run the process in a new thread, is it?
      Could I run the dialog in a new thread?

      Thank in advance.

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please provide a minimal, compilable example of your problem.
      How do you try to stop the process - I don't see a function in the documenation. There is just a function/slot to kill the process without any chance for the process to handle it somehow.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Please provide a minimal, compilable example of your problem.
        How do you try to stop the process - I don't see a function in the documenation. There is just a function/slot to kill the process without any chance for the process to handle it somehow.

        M Offline
        M Offline
        medihech
        wrote on last edited by
        #3

        @Christian-Ehrlicher

        void Run(bool bExec)
        {

        while (bExec)
        {
        ///Execute process
        }
        }

        main:
        //setup dialog
        //connect dialog button clicked to slot cancel
        dialog->show();

        cancel slot:
        //update bool exec to false

        user should be able to cancel the process by clicking the cancel button

        Christian EhrlicherC 1 Reply Last reply
        0
        • M medihech

          @Christian-Ehrlicher

          void Run(bool bExec)
          {

          while (bExec)
          {
          ///Execute process
          }
          }

          main:
          //setup dialog
          //connect dialog button clicked to slot cancel
          dialog->show();

          cancel slot:
          //update bool exec to false

          user should be able to cancel the process by clicking the cancel button

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          This is not even pseudo-code...
          How do you start the process, how do you try to stop it (or kill since stop can not work as there is no QProcess function for it).

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          M 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            This is not even pseudo-code...
            How do you start the process, how do you try to stop it (or kill since stop can not work as there is no QProcess function for it).

            M Offline
            M Offline
            medihech
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            Sorry, I did not explain it very well.
            The question I have is I want to run a process in background and at the same time, I should be able to stop it from a dialog . Is it possible?

            I do not have a code because I am not sure how to do it. I was thinking in use a thread. Could you give me some details to implement it?

            Thanks.

            JonBJ Christian EhrlicherC 2 Replies Last reply
            0
            • M medihech

              @Christian-Ehrlicher

              Sorry, I did not explain it very well.
              The question I have is I want to run a process in background and at the same time, I should be able to stop it from a dialog . Is it possible?

              I do not have a code because I am not sure how to do it. I was thinking in use a thread. Could you give me some details to implement it?

              Thanks.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @medihech
              In the slots section of QProcess you have kill() and terminate(). What else are you looking for? And no need for any separate threads, won't help.

              When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.

              Don't know what you're seeing. What signal, that for the click? Unless your computer is very busy running the other process so it doesn't service the request promptly. Start with a qDebug() in your clicked handler so you know when it's called.

              Note that your dialog->show() means it's (presumably) a modeless dialog (oh, actually your title says you have set it modal). You still have to allow the event loop to run. Can't tell from your code, but if your while (bExec) blocks the event loop that might be a problem. Like I said, start by verifying how promptly you get the clicked signal.

              Ah, hang on:

              cancel slot:
              //update bool exec to false
              

              Just updating bExec to exit the while loop is not enough to kill the spawned process. And I don't know what your while (bExec) is looping on if you have spawned a sub-process.

              M 1 Reply Last reply
              1
              • JonBJ JonB

                @medihech
                In the slots section of QProcess you have kill() and terminate(). What else are you looking for? And no need for any separate threads, won't help.

                When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.

                Don't know what you're seeing. What signal, that for the click? Unless your computer is very busy running the other process so it doesn't service the request promptly. Start with a qDebug() in your clicked handler so you know when it's called.

                Note that your dialog->show() means it's (presumably) a modeless dialog (oh, actually your title says you have set it modal). You still have to allow the event loop to run. Can't tell from your code, but if your while (bExec) blocks the event loop that might be a problem. Like I said, start by verifying how promptly you get the clicked signal.

                Ah, hang on:

                cancel slot:
                //update bool exec to false
                

                Just updating bExec to exit the while loop is not enough to kill the spawned process. And I don't know what your while (bExec) is looping on if you have spawned a sub-process.

                M Offline
                M Offline
                medihech
                wrote on last edited by
                #7

                @JonB
                Thanks, but I dont understand completely.

                I need to cancel the process and continue it from the dialog several time because it is a long process.
                I could send a code it is necessary, but it did not work.

                JonBJ 1 Reply Last reply
                0
                • M medihech

                  @JonB
                  Thanks, but I dont understand completely.

                  I need to cancel the process and continue it from the dialog several time because it is a long process.
                  I could send a code it is necessary, but it did not work.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @medihech said in Problem with a modal dialog connecting with a process:

                  I need to cancel the process and continue it from the dialog several time because it is a long process.

                  Did you try kill()/terminate()? Did you verify when your clicked slot is getting called as I mentioned a couple of times? I don't know what there is not to understand, if you want to kill a process on a click then just do so.

                  1 Reply Last reply
                  0
                  • M medihech

                    @Christian-Ehrlicher

                    Sorry, I did not explain it very well.
                    The question I have is I want to run a process in background and at the same time, I should be able to stop it from a dialog . Is it possible?

                    I do not have a code because I am not sure how to do it. I was thinking in use a thread. Could you give me some details to implement it?

                    Thanks.

                    Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by Christian Ehrlicher
                    #9

                    @medihech said in Problem with a modal dialog connecting with a process:

                    . Is it possible?

                    Yes. See the documentation on how to start a process.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    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