[SOLVED] QLabel and Segmentation fault...
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:
Code:
#include <QWidget>
#include <QtGui>
class MyGraphicView
: public QWidget {
Q_OBJECT
public:
MyGraphicView
(QWidget *parent
= 0);
private:
void updateImageInformation();
};
//////////////////////// CPP-File ////////////////////////
#include "MyGraphicView.h"
#include <QtGui>
MyGraphicView
::MyGraphicView(QWidget *parent
) : {
[...]
info_filesize
= new QLabel(this);
[...]
info_filesize->setText("KB"); // <- works!!!
}
void MyGraphicView::updateImageInformation()
{
info_filesize->setText("----"); // <- SIGSEGV
}
and GDB says:
Code:
(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
Re: QLabel and Segmentation fault...
Could you show the backtrace after the crash?
Re: QLabel and Segmentation fault...
Do you have by any chance another info_filesize declared in the constructor?
Re: QLabel and Segmentation fault...
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
}
Re: QLabel and Segmentation fault...
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:
Code:
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
Re: [SOLVED] QLabel and Segmentation fault...
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.