Results 1 to 9 of 9

Thread: Seg Fault

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Seg Fault

    I have the following code which compiles:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3. mainWindow::mainWindow(QWidget *parent): QMainWindow(parent)
    4. {
    5. detailsText = new QTextEdit();
    6. listTable = new QTableView();
    7. mainSplitter = new QSplitter(Qt::Horizontal,this);
    8. mainSplitter->addWidget(listTable);
    9. mainSplitter->addWidget(detailsText);
    10. setCentralWidget(mainSplitter);
    11. }
    12.  
    13.  
    14. mainWindow::~mainWindow()
    15. {
    16. }
    To copy to clipboard, switch view to plain text mode 

    But the execution fires a seg fault. Why?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Seg Fault

    What exactly is the error message when u get the seg fault ?

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Seg Fault

    looks good, but it'is hard to say what's wrong. provide compilable example.

  4. #4
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Seg Fault

    Quote Originally Posted by giusepped View Post
    I have the following code which compiles:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3. mainWindow::mainWindow(QWidget *parent): QMainWindow(parent)
    4. {
    5. detailsText = new QTextEdit();
    6. listTable = new QTableView();
    7. mainSplitter = new QSplitter(Qt::Horizontal,this);
    8. mainSplitter->addWidget(listTable);
    9. mainSplitter->addWidget(detailsText);
    10. setCentralWidget(mainSplitter);
    11. }
    12.  
    13.  
    14. mainWindow::~mainWindow()
    15. {
    16. }
    To copy to clipboard, switch view to plain text mode 

    But the execution fires a seg fault. Why?

    It is very unlikely that the code above segfaults. Of course this is only the .cpp file. Any 'magic' in your .h file? main.cpp? Other files? What you always can try is to distclean and do a cleanbuild. If that does not help. gdb is your friend. Or should be soon.

  5. #5
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Seg Fault

    This is the header
    Qt Code:
    1. class QSplitter;
    2. class QTextEdit;
    3. class QTableView;
    4.  
    5. /**
    6. @author giuseppe <giuseppe@localhost.localdomain>
    7. */
    8. class mainWindow: public QMainWindow {
    9. Q_OBJECT
    10. public:
    11. mainWindow(QWidget *parent = 0);
    12.  
    13. ~mainWindow();
    14.  
    15.  
    16.  
    17.  
    18.  
    19.  
    20.  
    21. QSplitter *mainSplitter;
    22. QTextEdit *detailsText;
    23. QTableView *listTable;
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    If I put
    Qt Code:
    1. QTableView *listTable = new QTableView
    To copy to clipboard, switch view to plain text mode 

    no seg faults appear
    I don't understand

  6. #6
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Seg Fault

    Quote Originally Posted by giusepped View Post
    no seg faults appear
    I don't understand
    Me neither. Should make no difference. In both cases the default constructor should be executed and the same object be created. Can you produce a stacktrace?

  7. #7
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Seg Fault

    Quote Originally Posted by giusepped View Post
    I have the following code which compiles:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3. mainWindow::mainWindow(QWidget *parent): QMainWindow(parent)
    4. {
    5. detailsText = new QTextEdit();
    6. listTable = new QTableView();
    7. mainSplitter = new QSplitter(Qt::Horizontal,this);
    8. mainSplitter->addWidget(listTable);
    9. mainSplitter->addWidget(detailsText);
    10. setCentralWidget(mainSplitter);
    11. }
    12.  
    13.  
    14. mainWindow::~mainWindow()
    15. {
    16. }
    To copy to clipboard, switch view to plain text mode 

    But the execution fires a seg fault. Why?
    Looks like the seg fault occurs while doing mainSplitter->addWidget(listTable); It would be great to see stacktrace.
    I'm a rebel in the S.D.G.

  8. #8
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Seg Fault

    How to do a stacktrace?
    g

  9. #9
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Seg Fault

    On Linux: gdb -c core <application> and then 'bt'. On Windows....who knows and cares.

Similar Threads

  1. qt-extended: Sigmentation Fault in uic.
    By zensei in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 10th March 2010, 12:56
  2. segmentation fault on mouse hover
    By elessaar in forum Qt Programming
    Replies: 6
    Last Post: 26th August 2008, 12:51
  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

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.