|
2Qter豆
流程是这样:相机采集图像到内存m_pRawBuffer,然后在label上显示出来
第一段代码是这样,不存在内存问题- void MainWindow::on_start_clicked()
- {
- // TODO: Add your command handler code here
- HVSTATUS status = STATUS_OK;
- /*
- * 启动数字摄像机采集图像到内存
- */
- uchar *ppBuf[1];
- ppBuf[0] = m_pRawBuffer;
- status = HVStartSnap(m_hhv, ppBuf,1);
- HV_VERIFY(status);
- if (HV_SUCCESS(status)) {
- m_bStart = TRUE;
- }
- QTimer *timer=new QTimer(this);
- connect(timer,SIGNAL(timeout()),this,SLOT(showcamera()));
- timer->start(100);
- }
- void MainWindow::showcamera()
- {
- QImage image(m_pRawBuffer,752,480,QImage::Format_Indexed8);
- QPixmap pixmap = QPixmap::fromImage(image);
- ui->label->move(30,30);
- ui->label->resize(400,400);
- ui->label->setPixmap(pixmap);
- }
复制代码 但是当我把相机单独写成一个类,然后在MainWindow里调用时候就出问题了,内存越来越大,只有当关闭mainwindow时才释放,代码如下:- //开始采集图像
- void MainWindow::on_actionStart_triggered()
- {
- camera.onSnapStart();
- QTimer *timer=new QTimer(this);
- ShowCamera();
- connect(timer,SIGNAL(timeout()),this,SLOT(ShowCamera()));
- timer->start(100);
- }
- //显示采集的图像
- void MainWindow::ShowCamera()
- {
- QImage image(aa->m_pRawBuffer,1000,700,QImage::Format_Indexed8);
- QPixmap pixmap;
- pixmap = QPixmap::fromImage(image);
- if(ui->action->isChecked())
- {
- QLabel *label=new QLabel(this);
- label->move(0,25);
- label->resize(1000,700);
- label->setPixmap(pixmap);
- label->show();
- }
- else
- {
- MyLabel *label=new MyLabel(this);
- label->move(0,25);
- label->resize(1000,700);
- label->setPixmap(pixmap);
- label->show();
- }
- }
复制代码 问题出在哪里?是相机存到内存的图片没有释放的原因还是因为这个new出来的MyLabel(子类化的一个QLabel)指针的问题?怎么解决?
|
最佳答案
查看完整内容
在MainWindow::ShowCamera()函数中,每100ms就new一个label,label的父类是MainWindow,只有当MainWindow关闭时才释放。
可以把label定义成MainWindow的成员变量啊,在构造函数new一次就可以了吧。
|