Results 1 to 7 of 7

Thread: segmentation fault on closing

  1. #1
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default segmentation fault on closing

    hello,

    i've got the following implementation:

    Qt Code:
    1. int main() {
    2.  
    3. GUI gui;
    4. gui.start();
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GUI::start(){
    2.  
    3. int argc = 0;
    4. char** argv = 0;
    5. m_Application = new QApplication( argc, argv );
    6.  
    7. m_MainWindow = new MainWindow();
    8.  
    9. m_MainWindow->show();
    10. m_Application->exec();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    so far, everything works fine. but as soon as i call the following function:
    Qt Code:
    1. void MainWindow::startDetection() {
    2.  
    3. ImageWindow* edgeDetectedImageWindow = new ImageWindow(this, m_ImageName, resultLocation, name);
    4. edgeDetectedImageWindow->show();
    5. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. #ifndef GUI_H
    2. #define GUI_H
    3.  
    4. #include <QSplashScreen>
    5. #include <QApplication>
    6.  
    7. #include "MainWindow/MainWindow.h"
    8.  
    9. #define THIS GUI
    10.  
    11. using namespace std;
    12.  
    13. class THIS{
    14.  
    15. // Q_OBJECT;
    16.  
    17. public:
    18. THIS();
    19. ~THIS();
    20. void start();
    21.  
    22. private:
    23. MainWindow* m_MainWindow;
    24. QApplication* m_Application;
    25.  
    26. };
    27.  
    28. #undef THIS
    29.  
    30. #endif /*GUI_H*/
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QStatusBar>
    6. #include <QDir>
    7. #include <QFrame>
    8. #include <QHBoxLayout>
    9. #include <QVBoxLayout>
    10. #include <QPushButton>
    11. #include <QScrollArea>
    12. #include <QLabel>
    13. #include <QFileDialog>
    14. #include <QMessageBox>
    15. #include <QMenuBar>
    16. #include <QMenu>
    17. #include <QAction>
    18. #include <QString>
    19. #include <QIcon>
    20.  
    21. #include "../../Modules/NevedgModule/NevedgModule.h"
    22. #include "../../Modules/Obj2PgmModule/Obj2PgmModule.h"
    23. #include "../../Modules/HystlineModule/HystlineModule.h"
    24. #include "../../Modules/PumaToQTConverterModule/PumaToQTConverterModule.h"
    25. #include "../../Modules/HasplitModule/HasplitModule.h"
    26. #include "../../Modules/FindRectangleModule/FindRectangleModule.h"
    27. #include "../../Modules/FindCircleModule/FindCircleModule.h"
    28. #include "../../Modules/GeometricObjectConverterModule/GeometricObjectConverterModule.h"
    29.  
    30. #include "ImageWindow/ImageWindow.h"
    31. #include "GraphicsWindow/GraphicsWindow.h"
    32.  
    33. #define THIS MainWindow
    34.  
    35. using namespace std;
    36.  
    37. class MainWindow : public QMainWindow {
    38.  
    39. Q_OBJECT;
    40.  
    41. public:
    42.  
    43. THIS();
    44. ~THIS();
    45.  
    46. private:
    47.  
    48. QString m_AppName;
    49. QString m_ImageName;
    50. QString m_ImageBaseName;
    51. QString m_ImagePath;
    52.  
    53. void loadModules();
    54. NevedgModule* m_NevedgModule;
    55. Obj2PgmModule* m_Obj2PgmModule;
    56. HystlineModule* m_HystlineModule;
    57. PumaToQTConverterModule* m_PumaToQTConverterModule;
    58. HasplitModule* m_HasplitModule;
    59. FindRectangleModule* m_FindRectangleModule;
    60. FindCircleModule* m_FindCircleModule;
    61. GeometricObjectConverterModule* m_GeometricObjectConverterModule;
    62.  
    63. void createMainWidget();
    64. QFrame* m_MainFrame;
    65. QHBoxLayout* m_MainLayout;
    66. QFrame* m_OperationsFrame;
    67. QVBoxLayout* m_OperationsLayout;
    68. QPushButton* m_LoadImagePushButton;
    69. QPushButton* m_StartDetectionPushButton;
    70. QScrollArea* m_InitialScrollArea;
    71. QLabel* m_InitialLabel;
    72.  
    73. void createMenus();
    74. QMenu* m_FileMenu;
    75. QAction* m_LoadImageAction;
    76. QAction* m_ExitAct;
    77. QMenu* m_EditMenu;
    78. QMenu* m_ViewMenu;
    79. QMenu* m_HelpMenu;
    80.  
    81. public slots:
    82.  
    83. void openImage();
    84. void loadImage(const QString &fileName);
    85. void startDetection();
    86.  
    87. };
    88.  
    89. #undef THIS
    90.  
    91. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef IMAGEWINDOW_H
    2. #define IMAGEWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QWidget>
    6. #include <QString>
    7. #include <QDir>
    8. #include <QIcon>
    9. #include <QScrollArea>
    10. #include <QLabel>
    11. #include <QMessageBox>
    12.  
    13. #define THIS ImageWindow
    14.  
    15. using namespace std;
    16.  
    17. class ImageWindow : public QMainWindow {
    18.  
    19. Q_OBJECT;
    20.  
    21. public:
    22.  
    23. THIS(QWidget* parent, QString &imageName, QString &imagePath, QString &operation);
    24. ~THIS();
    25.  
    26. private:
    27.  
    28. QString m_ImageName;
    29. QString m_ImagePath;
    30. QString m_Operation;
    31.  
    32. QScrollArea *m_ImageScrollArea;
    33. QLabel* m_ImageLabel;
    34.  
    35. public slots:
    36.  
    37. };
    38.  
    39. #undef THIS
    40.  
    41. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: segmentation fault on closing

    why cant you put your qapplication on stack in main()?

  3. #3
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault on closing

    Quote Originally Posted by MrDeath View Post
    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():
    Qt Code:
    1. int main() {
    2.  
    3. int argc = 0;
    4. char** argv = 0;
    5. QApplication* m_Application = new QApplication( argc, argv );
    6.  
    7. MainWindow* m_MainWindow = new MainWindow();
    8.  
    9. m_MainWindow->show();
    10. m_Application->exec();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    segmentation fault still appears on closing
    Last edited by harakiri; 7th July 2009 at 11:59.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: segmentation fault on closing

    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.

  5. #5
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault on closing

    Quote Originally Posted by MrDeath View Post
    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.
    Qt Code:
    1. int main(int argc, char *argv[]) {
    2.  
    3. QApplication m_Application( argc, argv );
    4.  
    5. MainWindow* m_MainWindow = new MainWindow();
    6.  
    7. m_MainWindow->show();
    8.  
    9. return m_Application.exec();
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    debugger result:
    Qt Code:
    1. (gdb) bt
    2. #0 0xb5cec2ed in ?? () from /lib/tls/i686/cmov/libc.so.6
    3. #1 0xb5cecfc0 in ?? () from /lib/tls/i686/cmov/libc.so.6
    4. #2 0xb5cadc1a in exit () from /lib/tls/i686/cmov/libc.so.6
    5. #3 0xb5c9577d in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
    6. #4 0x08056021 in _start () at ../sysdeps/i386/elf/start.S:119
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: segmentation fault on closing

    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.

  7. The following user says thank you to nish for this useful post:

    harakiri (8th July 2009)

  8. #7
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault on closing

    ok i'll test that, ty

    EDIT:

    that worked, thank you!

    Qt Code:
    1. void GraphicsWindow::closeEvent(QCloseEvent *event) {
    2.  
    3. delete this;
    4. event->accept();
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    fixed it, now the destructor is called
    Last edited by harakiri; 8th July 2009 at 14:06.

Similar Threads

  1. segmentation fault for no apparent reason
    By rishiraj in forum Newbie
    Replies: 1
    Last Post: 12th February 2009, 11:13
  2. segmentation fault
    By uchennaanyanwu in forum Newbie
    Replies: 3
    Last Post: 31st July 2008, 16:52
  3. Process aborted. Segmentation fault
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2007, 08:12
  4. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 16:35
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 16:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.