I have a QLabel containing an image that is being grabbed from an attached camera.
I have a grabbing thread running that retrieves the latest image, and then calls setPixmap()
, but the GUI often just stops updating.
The code in question:
QLabel *imageLabel;
QLabel *infoLabel;
...
imageLabel = new QLabel();
imageLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
imageLabel->setAlignment(Qt::AlignCenter);
imageLabel->setFixedHeight(720);
imageLabel->setFixedWidth(1280);
...
void QtWindow::grabbing_thread()
{
while (m_isRunning)
{
{
std::lock_guard<std::mutex> guard(m_updatingImage);
auto dispImage = padRunner.getDisplayImage();
if (dispImage.channels() == 3)
imageLabel->setPixmap(QPixmap::fromImage(QImage(dispImage.data, dispImage.cols, dispImage.rows, dispImage.step, QImage::Format_RGB888)));
else
imageLabel->setPixmap(QPixmap::fromImage(QImage(dispImage.data, dispImage.cols, dispImage.rows, dispImage.step, QImage::Format_RGBA8888)));
imageLabel->update();
}
infoLabelText = date::format("%T", std::chrono::system_clock::now()) + "\n";
infoLabel->update();
using namespace std::chrono_literals;
std::this_thread::sleep_for(15ms);
}
}
This works some of the time, and then it just freezes. But if I take my whole window, and literally move it around a bit, it restarts the display, and shows the latest frames again. I have no idea what to do to properly keep running (the camera is definitely running, the grabbing thread keeps acquiring images, the QtWindow just does not update its display).
Note: dispImage
is a cv::Mat