A error about QLabel::setText(const QString &) ?

81 views
Skip to first unread message

Kermit Mei

unread,
Feb 27, 2009, 10:16:44 AM2/27/09
to qt-c...@googlegroups.com, qt-in...@trolltech.com
Hello! In my widget I defined the following method, and all the label_** in
it is the type of QLabel.


void ResultWidget::setInfo(const QString &str11,const QString &str12,
const QString &str21,const QString &str22,
const QString &str31,const QString &str32) {
label_11->setText(str11);
label_12->setText(str12);

label_21->setText(str21);
label_22->setText(str22);

label_31->setText(str31);
label_32->setText(str32);

}

After make the project, everything goes well, but when I run it, the program
broke down here. The gdb output is:

Program received signal SIGSEGV, Segmentation fault.
QLabel::setText (this=0x0, text=@0xbfc70874) at widgets/qlabel.h:155
155 widgets/qlabel.h: No such file or directory.
in widgets/qlabel.h


And the stack of the program are:
(gdb) bt
#0 QLabel::setText (this=0x0, text=@0xbfc70874) at widgets/qlabel.h:155
#1 0xb7f28e7f in ResultWidget::setInfo (this=0x80c7368, str11=@0xbfc70874,
str12=@0xbfc70870, str21=@0xbfc7086c, str22=@0xbfc70868,
str31=@0xbfc70864, str32=@0xbfc70860)
at /home/kermit/Project/QFreeRecite/src/gui/ResultWidget.cpp:20
... ...

I don't know why this takes errors. All the arguments I put into the arglist
is standard QString type.

What may cause it?

Thanks.
Kermit Mei

Kermit Mei

unread,
Feb 27, 2009, 10:32:13 AM2/27/09
to Guido Moonen, qt-c...@googlegroups.com, qt-in...@trolltech.com
Guido Moonen wrote:
> Hi Kermit,
>
> It seems one of the label_xx pointers is still NULL, hence the this=0x0
> in the QLabel::setText.
>
> Have you initialized these labels?
>
> otherwise try to protect the calls using
>
> if (label_xx != NULL)
> label_xx->setText(strxx);
>
> With kind regards,
> Guido Moonen
>
>
Oh,yes. I just forgot to call setuiUi(this).
Thank you!

Reply all
Reply to author
Forward
0 new messages