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. QCoreApplications::processEvent() takes a lot of time when I use a background photo.

QCoreApplications::processEvent() takes a lot of time when I use a background photo.

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 748 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.
  • T Offline
    T Offline
    thegkhn
    wrote on last edited by thegkhn
    #1

    Good work everyone!

    I am writing a program with QT using C++. In the program I have a function to show OpenCV matrices in the background. In my main loop

    QImage img( vars.frame.data, vars.frame.cols, vars.frame.rows, vars.frame.step, QImage::Format_BGR888);
    vars.ui.background->setPixmap(QPixmap::fromImage(img));
    

    when I do this transformation and then

    QCoreApplication::processEvents();
    

    when I call this process, processEvents takes a significant amount of time, about 15-16 ms.

    But when I call the processEvents function directly without using background, it takes less than 1 ms.

    I also tried this with OpenGL Widget, QGraphicsView and QLabel and got no different result.

    How can I overcome this. Thank you in advance.

    Processor: Intel(R) Core(TM) i7-7560U CPU @ 2.40GHz
    Display Card: Intel(R) Iris(R) Plus Graphics 640

    C JonBJ 2 Replies Last reply
    0
    • T thegkhn

      Good work everyone!

      I am writing a program with QT using C++. In the program I have a function to show OpenCV matrices in the background. In my main loop

      QImage img( vars.frame.data, vars.frame.cols, vars.frame.rows, vars.frame.step, QImage::Format_BGR888);
      vars.ui.background->setPixmap(QPixmap::fromImage(img));
      

      when I do this transformation and then

      QCoreApplication::processEvents();
      

      when I call this process, processEvents takes a significant amount of time, about 15-16 ms.

      But when I call the processEvents function directly without using background, it takes less than 1 ms.

      I also tried this with OpenGL Widget, QGraphicsView and QLabel and got no different result.

      How can I overcome this. Thank you in advance.

      Processor: Intel(R) Core(TM) i7-7560U CPU @ 2.40GHz
      Display Card: Intel(R) Iris(R) Plus Graphics 640

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      @thegkhn It does not seem unreasonable to assume that if commenting this:

      QImage img( vars.frame.data, vars.frame.cols, vars.frame.rows, vars.frame.step, QImage::Format_BGR888);
      vars.ui.background->setPixmap(QPixmap::fromImage(img));
      

      removes ~15 ms of processing time, then that is how long this image conversion processing takes.

      Why are you calling QCoreApplication::processEvents at all?

      1 Reply Last reply
      1
      • T thegkhn

        Good work everyone!

        I am writing a program with QT using C++. In the program I have a function to show OpenCV matrices in the background. In my main loop

        QImage img( vars.frame.data, vars.frame.cols, vars.frame.rows, vars.frame.step, QImage::Format_BGR888);
        vars.ui.background->setPixmap(QPixmap::fromImage(img));
        

        when I do this transformation and then

        QCoreApplication::processEvents();
        

        when I call this process, processEvents takes a significant amount of time, about 15-16 ms.

        But when I call the processEvents function directly without using background, it takes less than 1 ms.

        I also tried this with OpenGL Widget, QGraphicsView and QLabel and got no different result.

        How can I overcome this. Thank you in advance.

        Processor: Intel(R) Core(TM) i7-7560U CPU @ 2.40GHz
        Display Card: Intel(R) Iris(R) Plus Graphics 640

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

        @thegkhn
        As @ChrisW67 has said. Start by separating the QPixmap::fromImage(img) from the setPixmap() to see which seems to be taking the time.

        I too don't know why or where you are calling processEvents(). But make sure you are calling it only once(?), not in a loop?

        T 1 Reply Last reply
        0
        • T Offline
          T Offline
          thegkhn
          wrote on last edited by
          #4

          When I run opencv outside of the main thread, I experience extreme performance loss. therefore I need to use both qt and opencv in the main thread. That's why I use it.

          J.HilkJ 1 Reply Last reply
          0
          • JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            Let us know if you fancy answering the questions/suggestions.

            1 Reply Last reply
            1
            • JonBJ JonB

              @thegkhn
              As @ChrisW67 has said. Start by separating the QPixmap::fromImage(img) from the setPixmap() to see which seems to be taking the time.

              I too don't know why or where you are calling processEvents(). But make sure you are calling it only once(?), not in a loop?

              T Offline
              T Offline
              thegkhn
              wrote on last edited by
              #6

              @JonB The conversion takes only 1 ms while the processEvents that I call after this conversion takes around 14 ms.

              JonBJ 1 Reply Last reply
              0
              • T thegkhn

                When I run opencv outside of the main thread, I experience extreme performance loss. therefore I need to use both qt and opencv in the main thread. That's why I use it.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @thegkhn said in QCoreApplications::processEvent() takes a lot of time when I use a background photo.:

                When I run opencv outside of the main thread, I experience extreme performance loss.

                fa3e3f4c-29ae-493f-a641-e245ac6e279c-image.png


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1
                • T thegkhn

                  @JonB The conversion takes only 1 ms while the processEvents that I call after this conversion takes around 14 ms.

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

                  @thegkhn said in QCoreApplications::processEvent() takes a lot of time when I use a background photo.:

                  while the processEvents that I call after this conversion takes around 14 ms.

                  @JonB said in QCoreApplications::processEvent() takes a lot of time when I use a background photo.:

                  But make sure you are calling it only once(?), not in a loop?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #9

                    processEvents is a crutch. Your grandma with a crutch will never be Flash. Sometimes processEvents helps to solve a problem, especially if performance is no concern. If you want performance, don't use processEvents!!!

                    Nobody can give you any more guidance because the code you have showed is not enough to analyze your problem. Maybe you have many slots queued that need to be handled. Certainly, if done properly having a separate thread of opencv will be faster (in total) because two threads with a lot of work is faster than a single thread. If you do too much synchronization between the GUI thread and the opencv thread, it'll be too slow. Use double buffering for the pixmap/image.

                    1 Reply Last reply
                    1

                    • Login

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