PDA

View Full Version : Strange segmentation fault



Lykurg
10th September 2006, 15:08
Hi,

I have following class:

#ifndef NORMALSEARCHWIDGET_H
#define NORMALSEARCHWIDGET_H

#include <QWidget>
#include <QBoxLayout>
class listBrowserWidget;

class normalSearchWidget : public QWidget
{
Q_OBJECT
public:
normalSearchWidget(QWidget *parent = 0);
~normalSearchWidget();
public slots:
void setLbTbDirection ( QBoxLayout::Direction direction );
private:
listBrowserWidget *lbw1;
listBrowserWidget *lbw2;
QBoxLayout *layout;
};
#endif
#include <QBoxLayout>

#include "normalsearchwidget.h"
#include "listbrowserwidget.h"

normalSearchWidget::normalSearchWidget(QWidget *parent)
: QWidget(parent)
{
layout = new QBoxLayout( QBoxLayout::TopToBottom );
layout->setMargin( 0 );
layout->setSpacing( 2 );

listBrowserWidget *lbw1 = new listBrowserWidget();
listBrowserWidget *lbw2 = new listBrowserWidget();

layout->addWidget(lbw1);
layout->addWidget(lbw2);

this->setLayout( layout );

// Next line works ( same line as in setLbTbDirection(QBoxLayout::Direction direction) )
lbw1->setDirection( QBoxLayout::TopToBottom );

// with this line I get and segmentation fault!
setLbTbDirection( QBoxLayout::TopToBottom );
}

normalSearchWidget::~normalSearchWidget()
{}

void normalSearchWidget::setLbTbDirection ( QBoxLayout::Direction direction )
{
lbw1->setDirection( QBoxLayout::TopToBottom );
}

As discribed in the commentar, I don't anderstand, why a statement in the constructor works and in a lokal function it causes an segFault. The function itself, without the line, works also perfekt.
I yet have deleted all generatet files, and have recompiled my program, but the error is still there.

Thanks for help,
Lykurg

jacek
10th September 2006, 15:54
listBrowserWidget *lbw1 = new listBrowserWidget();
listBrowserWidget *lbw2 = new listBrowserWidget();
These are local variables. normalSearchWidget::lbw1 and normalSearchWidget::lbw2 remain uninitialized.

Lykurg
10th September 2006, 16:01
These are local variables. normalSearchWidget::lbw1 and normalSearchWidget::lbw2 remain uninitialized.

Arrgg, you are right, of course! I hate failures like that...

Thanks
Lykurg

Popp
4th January 2009, 20:50
Thanks you too!
I had the same stupid failure...:mad:
... because of copy-pasting form Tutorials.