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!! -
@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.
-
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?
-
ecause I need to wait for the reply variable access to images
But that's no reason to block the event loop.
-
@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?