PDA

View Full Version : segmentation fault on closing



harakiri
7th July 2009, 11:02
hello,

i've got the following implementation:


int main() {

GUI gui;
gui.start();

}


void GUI::start(){

int argc = 0;
char** argv = 0;
m_Application = new QApplication( argc, argv );

m_MainWindow = new MainWindow();

m_MainWindow->show();
m_Application->exec();

}


so far, everything works fine. but as soon as i call the following function:

void MainWindow::startDetection() {

ImageWindow* edgeDetectedImageWindow = new ImageWindow(this, m_ImageName, resultLocation, name);
edgeDetectedImageWindow->show();
}


the whole application ist still working fine unless i close it: Segmentation fault
the debugger says:
(gdb) bt
#0 0xb5c28326 in ?? () from /lib/tls/i686/cmov/libc.so.6
#1 0xb5c28fc0 in ?? () from /lib/tls/i686/cmov/libc.so.6
#2 0xb5be9c1a in exit () from /lib/tls/i686/cmov/libc.so.6
#3 0xb5bd177d in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
#4 0x08056161 in _start () at ../sysdeps/i386/elf/start.S:119

anyone can help me with this matter?

here are the headers of the classes:


#ifndef GUI_H
#define GUI_H

#include <QSplashScreen>
#include <QApplication>

#include "MainWindow/MainWindow.h"

#define THIS GUI

using namespace std;

class THIS{

// Q_OBJECT;

public:
THIS();
~THIS();
void start();

private:
MainWindow* m_MainWindow;
QApplication* m_Application;

};

#undef THIS

#endif /*GUI_H*/


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStatusBar>
#include <QDir>
#include <QFrame>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QScrollArea>
#include <QLabel>
#include <QFileDialog>
#include <QMessageBox>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QString>
#include <QIcon>

#include "../../Modules/NevedgModule/NevedgModule.h"
#include "../../Modules/Obj2PgmModule/Obj2PgmModule.h"
#include "../../Modules/HystlineModule/HystlineModule.h"
#include "../../Modules/PumaToQTConverterModule/PumaToQTConverterModule.h"
#include "../../Modules/HasplitModule/HasplitModule.h"
#include "../../Modules/FindRectangleModule/FindRectangleModule.h"
#include "../../Modules/FindCircleModule/FindCircleModule.h"
#include "../../Modules/GeometricObjectConverterModule/GeometricObjectConverterModule.h"

#include "ImageWindow/ImageWindow.h"
#include "GraphicsWindow/GraphicsWindow.h"

#define THIS MainWindow

using namespace std;

class MainWindow : public QMainWindow {

Q_OBJECT;

public:

THIS();
~THIS();

private:

QString m_AppName;
QString m_ImageName;
QString m_ImageBaseName;
QString m_ImagePath;

void loadModules();
NevedgModule* m_NevedgModule;
Obj2PgmModule* m_Obj2PgmModule;
HystlineModule* m_HystlineModule;
PumaToQTConverterModule* m_PumaToQTConverterModule;
HasplitModule* m_HasplitModule;
FindRectangleModule* m_FindRectangleModule;
FindCircleModule* m_FindCircleModule;
GeometricObjectConverterModule* m_GeometricObjectConverterModule;

void createMainWidget();
QFrame* m_MainFrame;
QHBoxLayout* m_MainLayout;
QFrame* m_OperationsFrame;
QVBoxLayout* m_OperationsLayout;
QPushButton* m_LoadImagePushButton;
QPushButton* m_StartDetectionPushButton;
QScrollArea* m_InitialScrollArea;
QLabel* m_InitialLabel;

void createMenus();
QMenu* m_FileMenu;
QAction* m_LoadImageAction;
QAction* m_ExitAct;
QMenu* m_EditMenu;
QMenu* m_ViewMenu;
QMenu* m_HelpMenu;

public slots:

void openImage();
void loadImage(const QString &fileName);
void startDetection();

};

#undef THIS

#endif



#ifndef IMAGEWINDOW_H
#define IMAGEWINDOW_H

#include <QMainWindow>
#include <QWidget>
#include <QString>
#include <QDir>
#include <QIcon>
#include <QScrollArea>
#include <QLabel>
#include <QMessageBox>

#define THIS ImageWindow

using namespace std;

class ImageWindow : public QMainWindow {

Q_OBJECT;

public:

THIS(QWidget* parent, QString &imageName, QString &imagePath, QString &operation);
~THIS();

private:

QString m_ImageName;
QString m_ImagePath;
QString m_Operation;

QScrollArea *m_ImageScrollArea;
QLabel* m_ImageLabel;

public slots:

};

#undef THIS

#endif

nish
7th July 2009, 11:26
why cant you put your qapplication on stack in main()?

harakiri
7th July 2009, 11:34
why cant you put your qapplication on stack in main()?

the programm can be started without a gui, but i could skip that step using the GUI file

EDIT:
deleted the GUI file, main():

int main() {

int argc = 0;
char** argv = 0;
QApplication* m_Application = new QApplication( argc, argv );

MainWindow* m_MainWindow = new MainWindow();

m_MainWindow->show();
m_Application->exec();

}

segmentation fault still appears on closing

nish
7th July 2009, 13:59
first of all make argc and argv the parameters of main().. secondly use QApplication instead of QApplication*... third.. use a debugger to debug your app.. it will land the exact point where your app crashes... then see the call stack to trace the error.

harakiri
7th July 2009, 16:47
first of all make argc and argv the parameters of main().. secondly use QApplication instead of QApplication*... third.. use a debugger to debug your app.. it will land the exact point where your app crashes... then see the call stack to trace the error.


int main(int argc, char *argv[]) {

QApplication m_Application( argc, argv );

MainWindow* m_MainWindow = new MainWindow();

m_MainWindow->show();

return m_Application.exec();

}

debugger result:

(gdb) bt
#0 0xb5cec2ed in ?? () from /lib/tls/i686/cmov/libc.so.6
#1 0xb5cecfc0 in ?? () from /lib/tls/i686/cmov/libc.so.6
#2 0xb5cadc1a in exit () from /lib/tls/i686/cmov/libc.so.6
#3 0xb5c9577d in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
#4 0x08056021 in _start () at ../sysdeps/i386/elf/start.S:119

nish
8th July 2009, 01:06
ok .. the debugger is not helpful...

to trace the error... place a breakpoint in mainwindow destructor. then single step.. if it passes well.. then place on other destructors... if any destructor is not called than you have a problem.

harakiri
8th July 2009, 13:54
ok i'll test that, ty

EDIT:

that worked, thank you!


void GraphicsWindow::closeEvent(QCloseEvent *event) {

delete this;
event->accept();

}

fixed it, now the destructor is called