그래픽 뷰 QObject에 비디오를 표시하는 코드를 작성하고 있습니다. 그것은 다음과 같이 간다 : 당신이 볼 수 있듯이Qimage : 메모리 부족, null 이미지 반환
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() 10ms마다 첫 번째 클릭 후 타이머 슬롯 UpdateVideo()를 호출합니다. 비디오를 완벽하게 표시하고 싶지만 몇 초 후에 qt 생성자의 응용 프로그램 출력에 다음 오류가 나타납니다.
Qimage : 메모리 부족, null 이미지 반환.
그리고 나서 graphicsView 프레임이 비어있게됩니다. 메모리 누수가 어디 있는지 말해 줄 수 있어요?
타이머를 할당 할 때 어떤 일이 발생하는지 궁금합니다. 이후에 항상 삭제됩니까? –