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. Eventloop and QRenderCaptureReply running together in loop.exec() cannot return
Forum Updated to NodeBB v4.3 + New Features

Eventloop and QRenderCaptureReply running together in loop.exec() cannot return

Scheduled Pinned Locked Moved Solved General and Desktop
qt3drender
6 Posts 3 Posters 789 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.
  • Q Offline
    Q Offline
    qingcheng
    wrote on 13 Sept 2021, 00:40 last edited by
    #1
    auto camSelector = this->defaultFrameGraph()->findChild<Qt3DRender::QCamera*>();
    m_cap = new Qt3DRender::QRenderCapture(camSelector);
    m_returnImage = QImage();
    connect(this, &Q3DImageWindow::signalmyGetImage,[&](){
        QEventLoop loop;
        auto reply = m_cap->requestCapture();
        connect(reply, &Qt3DRender::QRenderCaptureReply::completed, [&] {
            m_returnImage = reply->image();
            //m_returnImage.save("this.jpg");
            qDebug()<<"ok in loop";
            loop.quit();
            });
        loop.exec();
        });
    

    Above is my running demo, now there is a problem, when the program runs to loop.exec(), it is stuck, I found in loop.exec() can not return when debugging, and the annotation line I saved this.jpg image can be captured normally.
    I want to ask what's wrong with my demo? Looking forward to your reply!!

    J 1 Reply Last reply 13 Sept 2021, 05:33
    0
    • Q qingcheng
      13 Sept 2021, 00:40
      auto camSelector = this->defaultFrameGraph()->findChild<Qt3DRender::QCamera*>();
      m_cap = new Qt3DRender::QRenderCapture(camSelector);
      m_returnImage = QImage();
      connect(this, &Q3DImageWindow::signalmyGetImage,[&](){
          QEventLoop loop;
          auto reply = m_cap->requestCapture();
          connect(reply, &Qt3DRender::QRenderCaptureReply::completed, [&] {
              m_returnImage = reply->image();
              //m_returnImage.save("this.jpg");
              qDebug()<<"ok in loop";
              loop.quit();
              });
          loop.exec();
          });
      

      Above is my running demo, now there is a problem, when the program runs to loop.exec(), it is stuck, I found in loop.exec() can not return when debugging, and the annotation line I saved this.jpg image can be captured normally.
      I want to ask what's wrong with my demo? Looking forward to your reply!!

      J Online
      J Online
      jeremy_k
      wrote on 13 Sept 2021, 05:33 last edited by
      #2

      @qingcheng said in Eventloop and QRenderCaptureReply running together in loop.exec() cannot return:

      auto camSelector = this->defaultFrameGraph()->findChild<Qt3DRender::QCamera*>();
      m_cap = new Qt3DRender::QRenderCapture(camSelector);
      m_returnImage = QImage();
      connect(this, &Q3DImageWindow::signalmyGetImage,[&](){
          QEventLoop loop;
          auto reply = m_cap->requestCapture();
          connect(reply, &Qt3DRender::QRenderCaptureReply::completed, [&] {
              m_returnImage = reply->image();
              //m_returnImage.save("this.jpg");
              qDebug()<<"ok in loop";
              loop.quit();
              });
          loop.exec();
          });
      

      Above is my running demo, now there is a problem, when the program runs to loop.exec(), it is stuck, I found in loop.exec() can not return when debugging, and the annotation line I saved this.jpg image can be captured normally.
      I want to ask what's wrong with my demo? Looking forward to your reply!!

      Why is the outer lambda starting a new event loop? Avoiding the main event loop and using recursive event loops are a frequent source of problems.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      Q 1 Reply Last reply 13 Sept 2021, 09:27
      2
      • J jeremy_k
        13 Sept 2021, 05:33

        @qingcheng said in Eventloop and QRenderCaptureReply running together in loop.exec() cannot return:

        auto camSelector = this->defaultFrameGraph()->findChild<Qt3DRender::QCamera*>();
        m_cap = new Qt3DRender::QRenderCapture(camSelector);
        m_returnImage = QImage();
        connect(this, &Q3DImageWindow::signalmyGetImage,[&](){
            QEventLoop loop;
            auto reply = m_cap->requestCapture();
            connect(reply, &Qt3DRender::QRenderCaptureReply::completed, [&] {
                m_returnImage = reply->image();
                //m_returnImage.save("this.jpg");
                qDebug()<<"ok in loop";
                loop.quit();
                });
            loop.exec();
            });
        

        Above is my running demo, now there is a problem, when the program runs to loop.exec(), it is stuck, I found in loop.exec() can not return when debugging, and the annotation line I saved this.jpg image can be captured normally.
        I want to ask what's wrong with my demo? Looking forward to your reply!!

        Why is the outer lambda starting a new event loop? Avoiding the main event loop and using recursive event loops are a frequent source of problems.

        Q Offline
        Q Offline
        qingcheng
        wrote on 13 Sept 2021, 09:27 last edited by
        #3

        @jeremy_k

        Thank you very much for your reply, because I need to wait for the reply variable access to images, only when the signal Qt3DRender: : QRenderCaptureReply: : when completed the trigger to the end of the event loop, if do not use the event loop, the picture is access to the background, Unable to obtain the model, do you have a better solution?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 13 Sept 2021, 09:28 last edited by
          #4

          ecause I need to wait for the reply variable access to images

          But that's no reason to block the event loop.

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

          Q 1 Reply Last reply 14 Sept 2021, 01:56
          0
          • C Christian Ehrlicher
            13 Sept 2021, 09:28

            ecause I need to wait for the reply variable access to images

            But that's no reason to block the event loop.

            Q Offline
            Q Offline
            qingcheng
            wrote on 14 Sept 2021, 01:56 last edited by
            #5

            @Christian-Ehrlicher
            Thank you very much for your reply, but if I do not block evenloop, the screenshot returned will only have background and no model, I would like to ask if you have a better solution? Whether the method of window screenshots or to solve the problem of only returning background images can be?

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qingcheng
              wrote on 15 Sept 2021, 06:35 last edited by
              #6

              I have already solved this problem, in fact, just call the function to capture the image twice to solve the problem, because the first time only has the background image, the second time is the required image!!

              1 Reply Last reply
              0

              6/6

              15 Sept 2021, 06:35

              • Login

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