在處理QGraphicsScene和QPixmap時,我解決了一個問題。 我順序顯示由相機捕獲的幀。 QTimer對象每100ms調用一次updateSingleView()函數。這是我的內部函數:從QGraphicsScene中刪除Qpixmap
void CCIGui::updateSingleView()
{
unsigned char *const img = PGRSystem->SnapShot();
QImage Img(img, 1024, 768, QImage::Format_RGB888);
scenes.at(0)->removeItem(scenes.at(0)->items().at(0));
scenes.at(0)->addPixmap(QPixmap::fromImage(Img));
ui_camViews.at(0).graphicsView->setScene(scenes.at(0));
delete [] img;
}
的GUI顯示相機的看法,但可惜的是有內存泄漏,呼籲scenes.at(0)->addPixmap(QPixmap::fromImage(Img));
當我以爲removeItem
函數應該摧毀舊的QPixmap,但顯然它不是。你知道爲什麼會發生泄漏以及如何解決它?
什麼版本的Qt?我在4.6中遇到了一些麻煩。?在Windows上。 – sje397 2010-11-24 09:12:10
我正在使用Qt版本4.6.3。 – Marcin 2010-11-24 09:24:34