I am very new to Qt and OpenCV and am creating a project integrating both. The problem I am running into is that I have a button to load a file, which uses QFileDialog. The whole thing runs smoothly and my file gets loaded. However, it crashes if I click the load button a second time. It seems like the problem occurs at the call to QFileDialog::getOpenFileName, but I need an expert opinion.
This is the function for the button click.
void MainWindow::on_pushButton_clicked()
{
QFileDialog dialog(this);
dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)"));
dialog.setViewMode(QFileDialog::Detail);
// dialog.setAttribute(Qt::WA_DeleteOnClose);
// dialog.DontUseNativeDialog;
filename = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Images (*.png *.xpm *.jpg)"));
imageObject = new QImage();
imageObject->load(filename);
image = QPixmap::fromImage(*imageObject);
scene = new QGraphicsScene(this);
scene->addPixmap(image);
scene->setSceneRect(image.rect());
ui->graphicsView->setScene(scene);
ui->graphicsView->fitInView(scene->sceneRect(),Qt::KeepAspectRatio);
cvHandler = new OpenCVHandler(filename.toStdString());
}
I have already tried both the lines that are commented out. My search also turned up nothing that I could understand easily:
Crash when calling getOpenFileName from QItemDelegate's custom editor
QFileDialog opens a second (possibly parent) unwanted window
Qt File Dialog Rendered Incorrectly and Crashes
If at all relevant, I am on an Ubuntu 16.04 LTS system.
Thank you