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. How to run background process when a Dialog is showed

How to run background process when a Dialog is showed

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 2.2k Views 3 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.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by
    #1

    I tried to run a process when a dialog is showed, But it didnt work . I want to show an dialog and at the same time i want to run the background process also , in which way this can be done ?

    ODБOïO jsulmJ 2 Replies Last reply
    0
    • ManiRonM ManiRon

      I tried to run a process when a dialog is showed, But it didnt work . I want to show an dialog and at the same time i want to run the background process also , in which way this can be done ?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi
      @ManiRon said in How to run background process when a Dialog is showed:

      I tried to run a process when a dialog is showed

      how ?

      @ManiRon said in How to run background process when a Dialog is showed:

      But it didnt work

      more precisely ?

      @ManiRon said in How to run background process when a Dialog is showed:

      i want to run the background process also

      reimplement the showEvent and run your task/code in QConcurent or QThread

      jsulmJ 1 Reply Last reply
      1
      • ODБOïO ODБOï

        hi
        @ManiRon said in How to run background process when a Dialog is showed:

        I tried to run a process when a dialog is showed

        how ?

        @ManiRon said in How to run background process when a Dialog is showed:

        But it didnt work

        more precisely ?

        @ManiRon said in How to run background process when a Dialog is showed:

        i want to run the background process also

        reimplement the showEvent and run your task/code in QConcurent or QThread

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @LeLev said in How to run background process when a Dialog is showed:

        reimplement the showEvent and run your task/code in QConcurent or QThread

        No need to use threads here as QProcess has an asynchronous API

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        ODБOïO 1 Reply Last reply
        4
        • ManiRonM ManiRon

          I tried to run a process when a dialog is showed, But it didnt work . I want to show an dialog and at the same time i want to run the background process also , in which way this can be done ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ManiRon said in How to run background process when a Dialog is showed:

          in which way this can be done ?

          Using QProcess. So, please show what you did and tell us what did not work.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • jsulmJ jsulm

            @LeLev said in How to run background process when a Dialog is showed:

            reimplement the showEvent and run your task/code in QConcurent or QThread

            No need to use threads here as QProcess has an asynchronous API

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #5

            @jsulm said in How to run background process when a Dialog is showed:

            No need to use threads here as QProcess has an asynchronous API

            sorry, my bad, i thought @ManiRon was referring to some code/method by 'process'

            ManiRonM 1 Reply Last reply
            0
            • ODБOïO ODБOï

              @jsulm said in How to run background process when a Dialog is showed:

              No need to use threads here as QProcess has an asynchronous API

              sorry, my bad, i thought @ManiRon was referring to some code/method by 'process'

              ManiRonM Offline
              ManiRonM Offline
              ManiRon
              wrote on last edited by
              #6

              @LeLev said in How to run background process when a Dialog is showed:

              No need to use threads here as QProcess has an asynchronous API

              Process means in this case i meant the tasks that are done by me

              JonBJ 1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi
                What do you want to run in the background ?
                Is it a single function ? or its some class that can process something?

                What did you already try ?

                Show some code.

                1 Reply Last reply
                0
                • ManiRonM ManiRon

                  @LeLev said in How to run background process when a Dialog is showed:

                  No need to use threads here as QProcess has an asynchronous API

                  Process means in this case i meant the tasks that are done by me

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

                  @ManiRon said in How to run background process when a Dialog is showed:

                  Process means in this case i meant the tasks that are done by me

                  Don't forget that if you don't want/need to have a separate thread, you can show a modal dialog but not block by using modal.show() rather than modal.exec(), so you can still do work while modal displayed.

                  ManiRonM 1 Reply Last reply
                  3
                  • JonBJ JonB

                    @ManiRon said in How to run background process when a Dialog is showed:

                    Process means in this case i meant the tasks that are done by me

                    Don't forget that if you don't want/need to have a separate thread, you can show a modal dialog but not block by using modal.show() rather than modal.exec(), so you can still do work while modal displayed.

                    ManiRonM Offline
                    ManiRonM Offline
                    ManiRon
                    wrote on last edited by ManiRon
                    #9

                    @JonB said in How to run background process when a Dialog is showed:

                    while

                    Actually i tried something like this

                            qDebug("Before SHow");
                            Modal.show();
                            qDebug("After SHow");
                    

                    Similarly for Exec

                            qDebug("Before SHow");
                            Modal.exec();
                            qDebug("After SHow");
                    

                    But what i observed was the first print was coming and later print was coming only when the Modal was closed

                    mrjjM 1 Reply Last reply
                    0
                    • ManiRonM ManiRon

                      @JonB said in How to run background process when a Dialog is showed:

                      while

                      Actually i tried something like this

                              qDebug("Before SHow");
                              Modal.show();
                              qDebug("After SHow");
                      

                      Similarly for Exec

                              qDebug("Before SHow");
                              Modal.exec();
                              qDebug("After SHow");
                      

                      But what i observed was the first print was coming and later print was coming only when the Modal was closed

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @ManiRon
                      Hi
                      It's important to understand that
                      modal.exec() is a socalled blocking call.
                      It spins an event loop in there and
                      will first return once dialog is closed.

                      That means it will NOT execute the next line after it dialog is gone.

                      --
                      modal.show() on the other hand is NOT blocking and
                      will execute the next line as soon as show() has run and while the dialog is still being displayed.

                      ManiRonM 2 Replies Last reply
                      3
                      • mrjjM mrjj

                        @ManiRon
                        Hi
                        It's important to understand that
                        modal.exec() is a socalled blocking call.
                        It spins an event loop in there and
                        will first return once dialog is closed.

                        That means it will NOT execute the next line after it dialog is gone.

                        --
                        modal.show() on the other hand is NOT blocking and
                        will execute the next line as soon as show() has run and while the dialog is still being displayed.

                        ManiRonM Offline
                        ManiRonM Offline
                        ManiRon
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @ManiRon
                          Hi
                          It's important to understand that
                          modal.exec() is a socalled blocking call.
                          It spins an event loop in there and
                          will first return once dialog is closed.

                          That means it will NOT execute the next line after it dialog is gone.

                          --
                          modal.show() on the other hand is NOT blocking and
                          will execute the next line as soon as show() has run and while the dialog is still being displayed.

                          ManiRonM Offline
                          ManiRonM Offline
                          ManiRon
                          wrote on last edited by
                          #12

                          @mrjj I checked and it worked the way you specified

                          mrjjM 1 Reply Last reply
                          0
                          • ManiRonM ManiRon

                            @mrjj I checked and it worked the way you specified

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @ManiRon
                            Ok that is good. Its an important difference between
                            show() and exec()

                            ManiRonM 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @ManiRon
                              Ok that is good. Its an important difference between
                              show() and exec()

                              ManiRonM Offline
                              ManiRonM Offline
                              ManiRon
                              wrote on last edited by
                              #14

                              @mrjj said in How to run background process when a Dialog is showed:

                              show() and exec()

                              Yes thanks

                              JonBJ 1 Reply Last reply
                              0
                              • ManiRonM ManiRon

                                @mrjj said in How to run background process when a Dialog is showed:

                                show() and exec()

                                Yes thanks

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

                                @ManiRon
                                Just to be clear: it is precisely because modal.exec() does not return to the caller till after the dialog has been closed, while modal.show() lets the caller continue, (and you will later react via signal/slot to user closing dialog, documentation describes this behaviour) that I am saying you may be able to use show() so that your calling code can continue and do other processing without the need to create a separate thread. It depends on what other processing you need to do, it was just a heads-up.

                                1 Reply Last reply
                                2

                                • Login

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