Eventloop and QRenderCaptureReply running together in loop.exec() cannot return
-
wrote on 13 Sept 2021, 00:40 last edited by
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!! -
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!!wrote on 13 Sept 2021, 05:33 last edited by@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.
-
@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.
wrote on 13 Sept 2021, 09:27 last edited byThank 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?
-
ecause I need to wait for the reply variable access to images
But that's no reason to block the event loop.
-
ecause I need to wait for the reply variable access to images
But that's no reason to block the event loop.
wrote on 14 Sept 2021, 01:56 last edited by@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? -
wrote on 15 Sept 2021, 06:35 last edited by
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/6