Thanks guys, I think I'm following what you are saying. I just wanted to make sure that you both realized that the two functions I wrote are in two separate classes, one in the worker thread and one in the GUI thread. So, I was not really doing any paint calls in the worker thread. Are you saying that I shouldn't be calling SetImage, because SetImage's function belongs to a QWidget which is part of the main GUI thread? In that case, yes I can use Signal's and Slots to let the GUI thread become aware that it needs to do work. However, I was trying to stay away from Signal's and Slot's because I wanted to directly call the function instead of putting it in a queue.
// VideoStreamEngine is on "Worker Thread"
void VideoStreamEngine::run()
{
Image *img = NULL
while (true)
{
server->GetFrame(&img); // hangs until a frame is available
pParent->SetImage(img); // This is the GUI function that I want to call instead of using signals/slots
}
}
// -----------------------------------------------------
// VideoRenderer class is on "GUI Thread"
void VideoRenderer::SetImage(Image *img)
{
if (img != NULL)
{
image = ... // Some code to scale img into a 32-bit QImage
// Set QPixmap
screenLabel
->setPixmap
( QPixmap::fromImage(*image
) );
}
}
// VideoStreamEngine is on "Worker Thread"
void VideoStreamEngine::run()
{
Image *img = NULL
while (true)
{
server->GetFrame(&img); // hangs until a frame is available
pParent->SetImage(img); // This is the GUI function that I want to call instead of using signals/slots
}
}
// -----------------------------------------------------
// VideoRenderer class is on "GUI Thread"
void VideoRenderer::SetImage(Image *img)
{
if (img != NULL)
{
image = ... // Some code to scale img into a 32-bit QImage
// Set QPixmap
screenLabel->setPixmap( QPixmap::fromImage(*image) );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks