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. QPushButton only responds with QApplication::processEvents
Forum Updated to NodeBB v4.3 + New Features

QPushButton only responds with QApplication::processEvents

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 839 Views 2 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.
  • L Offline
    L Offline
    leinad
    wrote on last edited by
    #1

    Hi,

    I have an odd problem. I'm working on building a Qt application within a larger one which I don't have the code. This application allows you to build plugin dlls to work in conjunction with the larger application. It mostly works but the issue I'm having is I created a progress bar form that has a progress bar and a button. When I click the button there is no response when I do a lot of work in the main GUI thread. The progressBar does update appropriately. So, I then added a thread to off load the work to that thread hoping that when I click the button it would respond, but that too does not work. It appears that the only way to get a button response after clicking it is if the class that does all the work issues processEvents every so often. Problem is when that happens the main application I'm working under flashes because that too is a Qt application.

    My question is there a way I can force my application to go to the main GUI thread without using processEvents? It's weird that the progress bar is updating but the button does not respond.

    Thanks!

    Christian EhrlicherC 1 Reply Last reply
    0
    • L leinad

      @Pl45m4 OK, I'll try removing the DirectConnections.

      L Offline
      L Offline
      leinad
      wrote on last edited by
      #15

      @leinad Seems like DirectConnection had something to do with it. Thanks.

      1 Reply Last reply
      0
      • L leinad

        Hi,

        I have an odd problem. I'm working on building a Qt application within a larger one which I don't have the code. This application allows you to build plugin dlls to work in conjunction with the larger application. It mostly works but the issue I'm having is I created a progress bar form that has a progress bar and a button. When I click the button there is no response when I do a lot of work in the main GUI thread. The progressBar does update appropriately. So, I then added a thread to off load the work to that thread hoping that when I click the button it would respond, but that too does not work. It appears that the only way to get a button response after clicking it is if the class that does all the work issues processEvents every so often. Problem is when that happens the main application I'm working under flashes because that too is a Qt application.

        My question is there a way I can force my application to go to the main GUI thread without using processEvents? It's weird that the progress bar is updating but the button does not respond.

        Thanks!

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

        You somewhere block the Qt event loop. Looks like your attempt to move the stuff into a separate thread was not successful. Use a debugger to see whats going on in the main thread.

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

        L 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          You somewhere block the Qt event loop. Looks like your attempt to move the stuff into a separate thread was not successful. Use a debugger to see whats going on in the main thread.

          L Offline
          L Offline
          leinad
          wrote on last edited by
          #3

          @Christian-Ehrlicher I wish I could. The result is a dll that is copied into the plugin folder of the main system. It loads my dll and runs it. I can only place print statements to debug.

          Christian EhrlicherC 1 Reply Last reply
          0
          • L leinad

            @Christian-Ehrlicher I wish I could. The result is a dll that is copied into the plugin folder of the main system. It loads my dll and runs it. I can only place print statements to debug.

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

            Then write test cases so you can test it without the other application. How do you test your code??

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

            L 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Then write test cases so you can test it without the other application. How do you test your code??

              L Offline
              L Offline
              leinad
              wrote on last edited by
              #5

              @Christian-Ehrlicher I put print statements everywhere. I always used a debugger in the past for this project I can't.

              L 1 Reply Last reply
              0
              • L leinad

                @Christian-Ehrlicher I put print statements everywhere. I always used a debugger in the past for this project I can't.

                L Offline
                L Offline
                leinad
                wrote on last edited by
                #6

                @leinad If I use threads which happen to have a heavy workload, shouldn't the system relinquish time to the main GUI thread? It seems I can never get a button click response. What other method other than processEvents can I use to do this?

                SGaistS 1 Reply Last reply
                0
                • L leinad

                  @leinad If I use threads which happen to have a heavy workload, shouldn't the system relinquish time to the main GUI thread? It seems I can never get a button click response. What other method other than processEvents can I use to do this?

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Hi,

                  How are you using that thread ?
                  Did you implement the worker object approach ?
                  Reimplement the run method ?
                  Are you using signals and slots ?

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

                  L 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    How are you using that thread ?
                    Did you implement the worker object approach ?
                    Reimplement the run method ?
                    Are you using signals and slots ?

                    L Offline
                    L Offline
                    leinad
                    wrote on last edited by
                    #8

                    @SGaist Here is an example:

                    Worker *worker = new Worker;
                    QThread* Thread = new QThread;
                    Thread->setObjectName("Thread");
                    worker->moveToThread(Thread);
                    
                    connect(worker, SIGNAL(finished()), Thread, SLOT(quit()));
                    connect(worker, SIGNAL(finished()), Thread, SLOT(deleteLater()));
                    connect(Thread, SIGNAL(finished()), Thread, SLOT(deleteLater()));
                    connect(this, SIGNAL(sendExit()), worker, SLOT(exit()), Qt::DirectConnection);
                    Thread->start(); 
                    

                    I run a few threads and use signal slots for communication like sending data.

                    Christian EhrlicherC L 2 Replies Last reply
                    0
                    • L leinad

                      @SGaist Here is an example:

                      Worker *worker = new Worker;
                      QThread* Thread = new QThread;
                      Thread->setObjectName("Thread");
                      worker->moveToThread(Thread);
                      
                      connect(worker, SIGNAL(finished()), Thread, SLOT(quit()));
                      connect(worker, SIGNAL(finished()), Thread, SLOT(deleteLater()));
                      connect(Thread, SIGNAL(finished()), Thread, SLOT(deleteLater()));
                      connect(this, SIGNAL(sendExit()), worker, SLOT(exit()), Qt::DirectConnection);
                      Thread->start(); 
                      

                      I run a few threads and use signal slots for communication like sending data.

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

                      This is not a minimal, compilable example. It does not even start anything in the worker object.

                      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
                      1
                      • L leinad

                        @SGaist Here is an example:

                        Worker *worker = new Worker;
                        QThread* Thread = new QThread;
                        Thread->setObjectName("Thread");
                        worker->moveToThread(Thread);
                        
                        connect(worker, SIGNAL(finished()), Thread, SLOT(quit()));
                        connect(worker, SIGNAL(finished()), Thread, SLOT(deleteLater()));
                        connect(Thread, SIGNAL(finished()), Thread, SLOT(deleteLater()));
                        connect(this, SIGNAL(sendExit()), worker, SLOT(exit()), Qt::DirectConnection);
                        Thread->start(); 
                        

                        I run a few threads and use signal slots for communication like sending data.

                        L Offline
                        L Offline
                        leinad
                        wrote on last edited by
                        #10

                        @leinad The question I was asked is how do I start a thread with a worker object. This is how I start a thread and attach a worker object to it. I know the thread starts because I am able to send data between them. My code is complicated and integrated with a 3rd party source.
                        The original question is if I run threads that do a lot of processing, shouldn't at some point the system relinquish to the main GUI thread so it can process pushbuttons, etc? It seems the only way I can do that is to use processEvents every so often to interrupt the current processing so as to check if the button was pressed. I really hate doing that.

                        Pl45m4P 1 Reply Last reply
                        0
                        • L leinad

                          @leinad The question I was asked is how do I start a thread with a worker object. This is how I start a thread and attach a worker object to it. I know the thread starts because I am able to send data between them. My code is complicated and integrated with a 3rd party source.
                          The original question is if I run threads that do a lot of processing, shouldn't at some point the system relinquish to the main GUI thread so it can process pushbuttons, etc? It seems the only way I can do that is to use processEvents every so often to interrupt the current processing so as to check if the button was pressed. I really hate doing that.

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by
                          #11

                          @leinad said in QPushButton only responds with QApplication::processEvents:

                          The original question is if I run threads that do a lot of processing, shouldn't at some point the system relinquish to the main GUI thread so it can process pushbuttons, etc?

                          Then you dont understand how threads work... unless you are blocking, the system usually keeps hopping between threads. e.g 2s processing Thread A, 5s Thread C, 2s Thread B, 7s Thread C and then 1s Thread A again.


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          L 1 Reply Last reply
                          0
                          • Pl45m4P Pl45m4

                            @leinad said in QPushButton only responds with QApplication::processEvents:

                            The original question is if I run threads that do a lot of processing, shouldn't at some point the system relinquish to the main GUI thread so it can process pushbuttons, etc?

                            Then you dont understand how threads work... unless you are blocking, the system usually keeps hopping between threads. e.g 2s processing Thread A, 5s Thread C, 2s Thread B, 7s Thread C and then 1s Thread A again.

                            L Offline
                            L Offline
                            leinad
                            wrote on last edited by
                            #12

                            @Pl45m4 Right, but eventually it should go back to the main thread correct? I'm not sure what you mean by blocking? None of the threads are stuck on anything, they just run one at a time but they do a lot of processing.

                            Pl45m4P 1 Reply Last reply
                            0
                            • L leinad

                              @Pl45m4 Right, but eventually it should go back to the main thread correct? I'm not sure what you mean by blocking? None of the threads are stuck on anything, they just run one at a time but they do a lot of processing.

                              Pl45m4P Offline
                              Pl45m4P Offline
                              Pl45m4
                              wrote on last edited by
                              #13

                              Hard to say what's going on exactly... unless you have an example where you can reproduce this behavior.
                              The code above doesn't help.

                              Also:

                              @leinad said in QPushButton only responds with QApplication::processEvents:

                              connect(this, SIGNAL(sendExit()), worker, SLOT(exit()), Qt::DirectConnection);

                              Better let Qt decide what type of connection is needed.
                              Forcing a DirectConnection when dealing with threads is in most of the cases a bad idea...


                              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                              ~E. W. Dijkstra

                              L 1 Reply Last reply
                              0
                              • Pl45m4P Pl45m4

                                Hard to say what's going on exactly... unless you have an example where you can reproduce this behavior.
                                The code above doesn't help.

                                Also:

                                @leinad said in QPushButton only responds with QApplication::processEvents:

                                connect(this, SIGNAL(sendExit()), worker, SLOT(exit()), Qt::DirectConnection);

                                Better let Qt decide what type of connection is needed.
                                Forcing a DirectConnection when dealing with threads is in most of the cases a bad idea...

                                L Offline
                                L Offline
                                leinad
                                wrote on last edited by
                                #14

                                @Pl45m4 OK, I'll try removing the DirectConnections.

                                L 1 Reply Last reply
                                0
                                • L leinad

                                  @Pl45m4 OK, I'll try removing the DirectConnections.

                                  L Offline
                                  L Offline
                                  leinad
                                  wrote on last edited by
                                  #15

                                  @leinad Seems like DirectConnection had something to do with it. Thanks.

                                  1 Reply Last reply
                                  0
                                  • L leinad has marked this topic as solved on

                                  • Login

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