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 809 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 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!!

    jeremy_kJ 1 Reply Last reply
    0
    • Q qingcheng
      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!!

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on 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
      2
      • jeremy_kJ jeremy_k

        @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 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
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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
          0
          • Christian EhrlicherC Christian Ehrlicher

            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 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 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

              • Login

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