I’ve been debugging a segmentation fault that happens when closing a Qt application composed of several projects. We ended up trying this very simple test:
main.cpp:
#include <QApplication>
#include <QMainWindow>
int main(int argc, char *argv[])
{
// Method 1: CLOSES CORRECTLY
/*QApplication a(argc, argv);
QMainWindow w;
w.show();
return a.exec();*/
// Method 2: CAUSES SEGFAULT
QApplication *a = new QApplication(argc, argv);
QMainWindow *w = new QMainWindow();
w->show();
return a->exec();
}
Project file:
QT += widgets
TARGET = test
TEMPLATE = app
SOURCES += main.cpp
I realized that the first method (commented code), always closes correctly and without errors while the second method which uses pointers causes a segfault on exit. This seems to happen randomly. This behavior appeared after migrating from Qt 4.6 to Qt 5.0.1, on CentOS 6.4.
Anyone would have an idea why the method using pointers does not work correctly anymore? Is this method valid? Is this behavior normal?
↧