I have a Qt (v 6.6.2) application where I'm trying to open a file dialog and let the user select one or more files. However, my application crashes after the file dialog is closed, regardless of whether files were selected or not. Here's a minimal version of my code:
#include <QFileDialog>
#include <QStringList>
#include <iostream>
#include <QApplication>
void LoadFile() {
QStringList files = QFileDialog::getOpenFileNames(
nullptr,
"Select one or more files to open",
"/home",
"Images (*.png *.xpm *.jpg)");
if (!files.isEmpty()) {
for (const auto& file : files) {
std::cout << "Selected file: " << file.toStdString() << std::endl;
}
} else {
std::cout << "No files were selected." << std::endl;
}
std::cout << "CRASH TEST" << std::endl;
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
LoadFile();
return app.exec();
}
The application crashes after the file dialog is closed. And I never get a console output
I've tried catching exceptions, but none are thrown. Any ideas why this might be happening?
Well this is what helped me for developping QT-APP in VSCODE-Environment. The Path to QT is hardcoded, but maybe someone has a more dynamic solution?
CMakeLists.txt: