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. Signals/Slots how to update grahpicsView (May be a macOS X only problem / bug)
QtWS25 Last Chance

Signals/Slots how to update grahpicsView (May be a macOS X only problem / bug)

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 550 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.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by ademmler
    #1

    Hi to all,

    I have created a minimal example for my problem. I draw colors to a graphics view scene in between I launch a subprocess. I use signals and slots for all this.

    a) The scene does not get updated - except I use QApplication::processEvents.
    As far a I have learned this is not recommended.
    What command I should use to update?

    b) Should I update the scene, the element or the graphics view?

    c) How can I get all statusbar messages be displayed?

    I don't know why I can't paste it here. Maybe it is to much.
    A minimal example here: http://files.lacunasolutions.com/various/QtMinimalLoops.zip

    thx for help and hints
    Alexander

    ademmlerA 1 Reply Last reply
    0
    • ademmlerA ademmler

      Hi to all,

      I have created a minimal example for my problem. I draw colors to a graphics view scene in between I launch a subprocess. I use signals and slots for all this.

      a) The scene does not get updated - except I use QApplication::processEvents.
      As far a I have learned this is not recommended.
      What command I should use to update?

      b) Should I update the scene, the element or the graphics view?

      c) How can I get all statusbar messages be displayed?

      I don't know why I can't paste it here. Maybe it is to much.
      A minimal example here: http://files.lacunasolutions.com/various/QtMinimalLoops.zip

      thx for help and hints
      Alexander

      ademmlerA Offline
      ademmlerA Offline
      ademmler
      wrote on last edited by
      #2

      Here is the main part of my example code.

      void MainWindow::slotDoSomething(int i)
      {    
          ui->statusbar->showMessage("Pause at: " + QString::number(i), 0);
      
          //QApplication::processEvents();
      
          QThread::sleep(1);
      }
      
      void MainWindow::slotPaintColor( int i){
          QPixmap pix(ui->graphicsView->size());
          pix.fill(QColor(colors[i].R, colors[i].G, colors[i].B));
          pixmap.setPixmap(pix);
          pixmap.update();
      }
      
      void MainWindow::on_startButton_released()
      {
          ui->statusbar->showMessage("Start loop ...", 0);
      
          for( int i = 0; i < 5; i++ ) {
      
              ui->statusbar->showMessage("Paint color: " + QString::number(i), 0);
      
              emit slotPaintColor(i);
      
              ui->statusbar->showMessage("Start subprocess now: " + QString::number(i), 0);
      
              emit slotDoSomething(i);
          }
      }
      
      1 Reply Last reply
      0
      • JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @ademmler said in Signals/Slots how to update grahpicsView:

        The scene does not get updated - except I use QApplication::processEvents.

        Your sample uses QThread::sleep(1);. This is problematic. Simply do not use anything like sleep().

        So long as you implement the running of your subprocess via the asynchronous signals & slots methods of QProcess --- and not QProcess::execute() or QProcess::waitForFinished() --- there will be no blocking/freezing. Basically, do everything with signals & slots, not blocking calls like these or QThread::sleep().

        ademmlerA 1 Reply Last reply
        1
        • JonBJ JonB

          @ademmler said in Signals/Slots how to update grahpicsView:

          The scene does not get updated - except I use QApplication::processEvents.

          Your sample uses QThread::sleep(1);. This is problematic. Simply do not use anything like sleep().

          So long as you implement the running of your subprocess via the asynchronous signals & slots methods of QProcess --- and not QProcess::execute() or QProcess::waitForFinished() --- there will be no blocking/freezing. Basically, do everything with signals & slots, not blocking calls like these or QThread::sleep().

          ademmlerA Offline
          ademmlerA Offline
          ademmler
          wrote on last edited by ademmler
          #4

          @JonB

          thx for your comment - I need to explain more about my example.

          1. The sleep replaces my original subroutine.
            In this one I do some measurements using a color measurement device.
            But this takes also some time to measure ... hence I added sleep for simulation this.

          2. The two processes of painting and measurement need to be in synchronization.
            If I use the suggested method does not work at all.

          3. My question was not about QThread or QProcess.

          My questions are still open and about using graphicsview properly:

          1. What signal can I get, after an element has been repainted?
          2. How can I force a repaint?
          3. On which of the three elements (grahicsView, scene, pixmap) I should do this repaint/update call?

          Regards Alexander

          ademmlerA 1 Reply Last reply
          0
          • ademmlerA ademmler

            @JonB

            thx for your comment - I need to explain more about my example.

            1. The sleep replaces my original subroutine.
              In this one I do some measurements using a color measurement device.
              But this takes also some time to measure ... hence I added sleep for simulation this.

            2. The two processes of painting and measurement need to be in synchronization.
              If I use the suggested method does not work at all.

            3. My question was not about QThread or QProcess.

            My questions are still open and about using graphicsview properly:

            1. What signal can I get, after an element has been repainted?
            2. How can I force a repaint?
            3. On which of the three elements (grahicsView, scene, pixmap) I should do this repaint/update call?

            Regards Alexander

            ademmlerA Offline
            ademmlerA Offline
            ademmler
            wrote on last edited by
            #5

            @JonB Can you help me with this also ?

            JonBJ 1 Reply Last reply
            0
            • ademmlerA ademmler

              @JonB Can you help me with this also ?

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

              @ademmler
              Not really, because as I said I don't see any need to try to do all this forced repainting etc.

              I know what you are trying to simulate with your use of QThread::sleep(1);, but it is the cause of the problem.

              What you should do, for your calculations or whatever it is that you will really do there, is one of:

              • If that code can do its work in the main thread via using signals use that. Just as an e.g., QProcess works that way.

              • Otherwise, put it in its own thread and simply have that raise signals when it wants to tell the UI thread something to act on.

              Now you have no blocking, and the UI thread remains "responsive" while the other thread is running. The other thread is not responsible for "forcing" updates in the UI, those happen when the UI thread gets its timeslice to run.

              That's how I would approach it, at least to see what performance is like.

              ademmlerA 1 Reply Last reply
              0
              • JonBJ JonB

                @ademmler
                Not really, because as I said I don't see any need to try to do all this forced repainting etc.

                I know what you are trying to simulate with your use of QThread::sleep(1);, but it is the cause of the problem.

                What you should do, for your calculations or whatever it is that you will really do there, is one of:

                • If that code can do its work in the main thread via using signals use that. Just as an e.g., QProcess works that way.

                • Otherwise, put it in its own thread and simply have that raise signals when it wants to tell the UI thread something to act on.

                Now you have no blocking, and the UI thread remains "responsive" while the other thread is running. The other thread is not responsible for "forcing" updates in the UI, those happen when the UI thread gets its timeslice to run.

                That's how I would approach it, at least to see what performance is like.

                ademmlerA Offline
                ademmlerA Offline
                ademmler
                wrote on last edited by ademmler
                #7

                @JonB

                If that code can do its work in the main thread via using signals use that. Just as an e.g., QProcess works that way.
                

                The process is not a "system process" - what's going on in the SDK of the measurement device is a "black box" for me.

                Otherwise, put it in its own thread and simply have that raise signals when it wants to tell the UI thread something to act on.
                

                For my minimal example this would mean "void MainWindow::slotDoSomething(int i)" will emit a signal to get the main process to "paint" the next color. Which is the invers version of my actual sample. right?

                I tried this out - but still - the color does not change without QApplication::processEvents();
                Hence again the question: how to get the colored pixmap to be updated ...

                Here is the actual code for download: http://files.lacunasolutions.com/various/QtMinimalLoopsV2.zip

                JonBJ 1 Reply Last reply
                0
                • ademmlerA ademmler

                  @JonB

                  If that code can do its work in the main thread via using signals use that. Just as an e.g., QProcess works that way.
                  

                  The process is not a "system process" - what's going on in the SDK of the measurement device is a "black box" for me.

                  Otherwise, put it in its own thread and simply have that raise signals when it wants to tell the UI thread something to act on.
                  

                  For my minimal example this would mean "void MainWindow::slotDoSomething(int i)" will emit a signal to get the main process to "paint" the next color. Which is the invers version of my actual sample. right?

                  I tried this out - but still - the color does not change without QApplication::processEvents();
                  Hence again the question: how to get the colored pixmap to be updated ...

                  Here is the actual code for download: http://files.lacunasolutions.com/various/QtMinimalLoopsV2.zip

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

                  @ademmler
                  I'm sorry, I don't download code.

                  As I said, the calculation ("measurement device") needs to be its own thread, so that it can block if it wants. That sends signals when it has something to say. The main GUI acts on that and does updates when its thread is running. I would not expect QApplication::processEvents() anywhere.

                  I leave it to you/others now, who perhaps can help you more.

                  ademmlerA 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @ademmler
                    I'm sorry, I don't download code.

                    As I said, the calculation ("measurement device") needs to be its own thread, so that it can block if it wants. That sends signals when it has something to say. The main GUI acts on that and does updates when its thread is running. I would not expect QApplication::processEvents() anywhere.

                    I leave it to you/others now, who perhaps can help you more.

                    ademmlerA Offline
                    ademmlerA Offline
                    ademmler
                    wrote on last edited by
                    #9

                    @JonB
                    Sorry Jon - I understand that you down download. But without the code you will not understand me.
                    I am already using signals and slots and the problem still exists. I think this is even a MacOS X related problem/bug, because on windows we do not have this issue.

                    How can I paste all code into this windows here? The amount of text seems to be limited ...

                    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