In a basic C++ Qt Widgets application, creating a QApplication on the stack or heap-allocating it directly in the main function works, but calling a function the heap-allocates a QApplication and using the returned pointer gives a segmentation fault:
#include <QtWidgets>
QApplication* create_application(int argc, char* argv[]) {
return new QApplication(argc, argv);
}
int main(int argc, char* argv[]) {
QApplication* app = create_application(argc, argv);
QWidget window;
window.show();
app->exec();
}
I think it's being automatically delete, but I can't figure out why.