我正在编写代码以在 graphicsView QObject 中显示视频。它是这样的:
void MainWindow::UpdateVideo()
{
cap >> frame;
cvtColor(frame, frame,CV_BGR2RGB);
QImage Qframe = QImage((uchar*) frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
QPointer<QGraphicsScene> VideoScene = new QGraphicsScene;
VideoScene->addPixmap(QPixmap::fromImage(Qframe));
ui->VideoView->setScene(VideoScene);
ui->VideoView->show();
}
void MainWindow::on_pushButton_2_clicked()
{
cap.open("test1.mpg");
if(!cap.isOpened())
cout<<"CANNOT OPEN FILE"<<endl; //or you can put some error message
QPointer<QTimer> UpdateVideo = new QTimer;
connect(UpdateVideo, SIGNAL(timeout()), this, SLOT(UpdateVideo()));
UpdateVideo->start(10);
}
如您所见,插槽 on_pushButton_2_clicked() 将在第一次单击后每隔 10 毫秒使用计时器调用插槽 UpdateVideo()。我想让视频完美显示,但几秒钟后,qt creator 的应用程序输出中出现以下错误:
Qimage:内存不足,返回空图像。
然后 graphicsView 框架变为空白。你能告诉我内存泄漏在哪里吗?