PDA

View Full Version : [SOLVED] QLabel and Segmentation fault...



Lykurg
4th October 2007, 10:21
Hi,

I have completely rebuild my project but get still a segmentation fault. I don't understand why, because the "setText()" works in the constructor but not in the function? Here is the relevant code:
#include <QWidget>
#include <QtGui>

class MyGraphicView : public QWidget
{
Q_OBJECT

public:
MyGraphicView(QWidget *parent = 0);

private:
void updateImageInformation();

QLabel *info_filesize;
};


//////////////////////// CPP-File ////////////////////////

#include "MyGraphicView.h"

#include <QtGui>

MyGraphicView::MyGraphicView(QWidget *parent) :
QWidget(parent)
{
[...]
info_filesize = new QLabel(this);
[...]
info_filesize->setText("KB"); // <- works!!!
}

void MyGraphicView::updateImageInformation()
{
info_filesize->setText("----"); // <- SIGSEGV
}
and GDB says:
(gdb) run
Starting program: /home/lykurg/workspace/cpp/workplace/ganesha/ganesha
[Thread debugging using libthread_db enabled]
[New Thread -1224829232 (LWP 9063)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1224829232 (LWP 9063)]
QLabel::setText (this=0x2f006c, text=@0xbf828400) at widgets/qlabel.h:154
154 widgets/qlabel.h: No such file or directory.
in widgets/qlabel.h
Current language: auto; currently c++
When I comment the "setText()" in updateImageInformation() out, the program starts and executes the constructor-setText without any problems.


Thanks,

Lykurg

wysota
4th October 2007, 11:55
Could you show the backtrace after the crash?

marcel
4th October 2007, 12:01
Do you have by any chance another info_filesize declared in the constructor?

rajesh
4th October 2007, 12:35
for safety you add following which I added in blue

MyGraphicView::MyGraphicView(QWidget *parent) :
QWidget(parent),info_filesize(NULL)
{
[...]
info_filesize = new QLabel(this);
[...]
info_filesize->setText("KB"); // <- works!!!
}

void MyGraphicView::updateImageInformation()
{
if(info_filesize)
info_filesize->setText("----"); // <- SIGSEGV
}

Lykurg
4th October 2007, 13:40
Hi,

the backtrace offers nothing new. Because I am at the time not connected to the internet with my laptop and have no usb stick around, here ist the handmade bt:
QLabel::setText (this=0x2f006c, text=@0xbf828400) at widgets/qlabel.h:154
MyGraphicView::updateImageInformation()
MyGraphicView::setImage()
MyGraphicView::MyGraphicView()
Ganesha:createGui()
Ganesha::Ganesha()
main()

@rajesh: Your code shows, that the label is not existing when the function is called. But why? Maybe it is because, the whole application is not shown? But the QGraphicsSceene in setImage(), which at least calls updateImageInformation(), is allready there, and the image in it is shown...

Still stange, but I am looking forward to find the real problem.

EDIT: Forgott about all, I am too ***! I have overlooked an updateImageInformation()-call in the constructor from previous work... damn.


Lykurg

rajesh
4th October 2007, 14:12
may be info_filesize not getting initialize in the constructor.
just put the breakpoint in constructor and in updateImageInformation()
and check the address of info_filesize, if it is not a valid address then you will get Segmentation fault. may be your pointer getting disturbed some where.