I hope I did something wrong. Maybe you can help me solve my old problem. I post my code here. My app is to display the camera output images in QGLWidget.
MyThread: in its run method, it does the while-loop
run()
{
while(flag)
{
IplImage *lp_color = t_camera.get_image();
myQLWidget->setCurrentImageIpl(lp_color);
cvReleaseImage(&lp_color);
}
}
run()
{
while(flag)
{
IplImage *lp_color = t_camera.get_image();
myQLWidget->setCurrentImageIpl(lp_color);
cvReleaseImage(&lp_color);
}
}
To copy to clipboard, switch view to plain text mode
MyQLWidget: in charge of updating the texture when it receives any image.
I am using SIGNAL & SLOT in MyQLWidget, because in method setCurrentImageIpl(), I cannot directly call updateGL(). This is because OpenGl & Thread issue... So in setCurrentImageIpl() I emit a SIGNAL to a SLOT, the SLOT will do updateGL() for me.
MyQLWidget::setCurrentImageIpl()
{
...(set image)
imageData = ...;
update = true;
emit newData();
}
MyQLWidget::setCurrentImageIpl()
{
...(set image)
imageData = ...;
update = true;
emit newData();
}
To copy to clipboard, switch view to plain text mode
newData is connect to SLOT updateImage()
MyQLWidget::updateImage()
{
this->updateGL();
}
MyQLWidget::paintGL()
{
if(update)
glTexSubImage2D = (.....imageData);
}
MyQLWidget::updateImage()
{
this->updateGL();
}
MyQLWidget::paintGL()
{
if(update)
glTexSubImage2D = (.....imageData);
}
To copy to clipboard, switch view to plain text mode
During displaying the first few frames that grasped by camera, my program crashes. Not every time. I don't know where is the problem. When it crashes, the reason is that the imageData is not set jet, so when update texture it crashes.
I set breakpoint, and found that in the first few steps, ...emit... executes twice, but updateImage() only once. Maybe this causes the crash, I am not sure.
Hard to explain what I did in my code here.
Bookmarks