PDA

View Full Version : Seg Fault



giusepped
22nd October 2008, 09:17
I have the following code which compiles:



#include "mainwindow.h"
#include <QtGui>
mainWindow::mainWindow(QWidget *parent): QMainWindow(parent)
{
detailsText = new QTextEdit();
listTable = new QTableView();
mainSplitter = new QSplitter(Qt::Horizontal,this);
mainSplitter->addWidget(listTable);
mainSplitter->addWidget(detailsText);
setCentralWidget(mainSplitter);
}


mainWindow::~mainWindow()
{
}




But the execution fires a seg fault. Why?

aamer4yu
22nd October 2008, 09:25
What exactly is the error message when u get the seg fault ?

spirit
22nd October 2008, 09:25
looks good, but it'is hard to say what's wrong. provide compilable example.

Kumosan
22nd October 2008, 09:31
I have the following code which compiles:



#include "mainwindow.h"
#include <QtGui>
mainWindow::mainWindow(QWidget *parent): QMainWindow(parent)
{
detailsText = new QTextEdit();
listTable = new QTableView();
mainSplitter = new QSplitter(Qt::Horizontal,this);
mainSplitter->addWidget(listTable);
mainSplitter->addWidget(detailsText);
setCentralWidget(mainSplitter);
}


mainWindow::~mainWindow()
{
}




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. ;)

giusepped
22nd October 2008, 09:45
This is the header


class QSplitter;
class QTextEdit;
class QTableView;

/**
@author giuseppe <giuseppe@localhost.localdomain>
*/
class mainWindow: public QMainWindow {
Q_OBJECT
public:
mainWindow(QWidget *parent = 0);

~mainWindow();







QSplitter *mainSplitter;
QTextEdit *detailsText;
QTableView *listTable;
};

#endif


If I put


QTableView *listTable = new QTableView


no seg faults appear
I don't understand

Kumosan
22nd October 2008, 12:54
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?

lyuts
22nd October 2008, 14:41
I have the following code which compiles:



#include "mainwindow.h"
#include <QtGui>
mainWindow::mainWindow(QWidget *parent): QMainWindow(parent)
{
detailsText = new QTextEdit();
listTable = new QTableView();
mainSplitter = new QSplitter(Qt::Horizontal,this);
mainSplitter->addWidget(listTable);
mainSplitter->addWidget(detailsText);
setCentralWidget(mainSplitter);
}


mainWindow::~mainWindow()
{
}




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.

giusepped
23rd October 2008, 04:48
How to do a stacktrace?
g

Kumosan
23rd October 2008, 09:12
On Linux: gdb -c core <application> and then 'bt'. On Windows....who knows and cares. :p