PDA

View Full Version : QLabel pointer - seg fault



Tomasz
26th November 2010, 12:47
Hello!

I've got some problems with QLabel and pointers. I've created window with 4 labels. Then in my include file I've got something like this:



class app : public QDialog
{
Q_OBJECT

public:
[...]

public slots:
[..]

private:
QLabel *myLabels[4];
};


In app.cpp I've got:



[...]
{
ui->setupUi(this);
[...]

myLabels[0]=ui->label1;
myLabels[1]=ui->label2;
myLabels[2]=ui->label3;
myLabels[3]=ui->label4;
}


And then I've got function:



bool app::myFunc()
{
for (int i=0; i<4; i++)
{
myLabels[i]->setText( "test" );
}
}


And myFunc() causes segmentation fault. Any idea why?

When I do:


ui->label1->setText( "test" );


Everything is OK.

thanks in advance
best regards
Tomasz

wysota
26th November 2010, 12:50
Please provide a minimal compilable example reproducing the problem.

FelixB
26th November 2010, 14:41
maybe you forgot to initialize your array?

maybe you call myFunc before assigning the labels to the array?

Tomasz
26th November 2010, 14:53
maybe you call myFunc before assigning the labels to the array?

I've analysed my code, and You're right. My stupid mistake.

thanks
best regards
Tomasz