Hi,
I'm fairly new to qt, I'm using qt creator on both linux and mac and the same code is causing the same problem on both platforms. Anyway I'm trying to display an image from a camera and while it is displaying it's also causing a memory leak which over time eventually crashes the computer. I've had a look online but can't seem to find anything on this. If I comment out the code that displays the image then the rest of the program works fine with no memory leak and no crash.
void MainWindow::display_image()
{
if(moving > 0) moving --;
get_camera(ui->horizontalSlider_scan_size->value(), ui->horizontalSlider_colour_threshold->value());
//--------------------------------------------------------------draw camera views
if(ui->checkBox_vis->isChecked()) {
ui->graphicsView_left_cam->setScene(left_cam_view);
ui->graphicsView_left_cam->show();
ui->graphicsView_left_cam->setSceneRect(0,0,image_width,image_height);
limage
= QImage(image_width, image_height,
QImage::Format_ARGB32);
#pragma omp parallel for
for(int x=0; x<image_width; x++) {
for(int y=0; y<image_height; y++) {
QRgb lvalue = qRgba(left_image[x][y][0], left_image[x][y][1], left_image[x][y][2], 255);
limage.setPixel(x,y,lvalue);
}
}
lpixmap
= QPixmap::fromImage(limage
);
left_cam_view->addPixmap(lpixmap);
}
void MainWindow::display_image()
{
if(moving > 0) moving --;
get_camera(ui->horizontalSlider_scan_size->value(), ui->horizontalSlider_colour_threshold->value());
//--------------------------------------------------------------draw camera views
if(ui->checkBox_vis->isChecked()) {
ui->graphicsView_left_cam->setScene(left_cam_view);
ui->graphicsView_left_cam->show();
ui->graphicsView_left_cam->setSceneRect(0,0,image_width,image_height);
limage = QImage(image_width, image_height, QImage::Format_ARGB32);
#pragma omp parallel for
for(int x=0; x<image_width; x++) {
for(int y=0; y<image_height; y++) {
QRgb lvalue = qRgba(left_image[x][y][0], left_image[x][y][1], left_image[x][y][2], 255);
limage.setPixel(x,y,lvalue);
}
}
lpixmap = QPixmap::fromImage(limage);
left_cam_view->addPixmap(lpixmap);
}
To copy to clipboard, switch view to plain text mode
So whats going on here is... I have an image which is stored in a matrix x by y by 3 (r,g,b) so I set the value of a pixel and then set that pixel in a Qimage.
So the user presses a button to start things off and that causes a hidden button to repeat which calls this function...
void MainWindow::on_pushButton_start_clicked()
{
ui->refresh->setDown(true);
ui->refresh->setAutoRepeat(true);
ui->refresh->setAutoRepeatInterval(50);
}
void MainWindow::on_refresh_clicked()
{
display_image();
}
void MainWindow::on_pushButton_start_clicked()
{
ui->refresh->setDown(true);
ui->refresh->setAutoRepeat(true);
ui->refresh->setAutoRepeatInterval(50);
}
void MainWindow::on_refresh_clicked()
{
display_image();
}
To copy to clipboard, switch view to plain text mode
Thats it, so why do I get the memory leak? what have I missed or misunderstood about this?
Cheers
Bookmarks