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:
{
Q_OBJECT
public:
[...]
public slots:
[..]
private:
};
class app : public QDialog
{
Q_OBJECT
public:
[...]
public slots:
[..]
private:
QLabel *myLabels[4];
};
To copy to clipboard, switch view to plain text mode
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;
}
[...]
{
ui->setupUi(this);
[...]
myLabels[0]=ui->label1;
myLabels[1]=ui->label2;
myLabels[2]=ui->label3;
myLabels[3]=ui->label4;
}
To copy to clipboard, switch view to plain text mode
And then I've got function:
bool app::myFunc()
{
for (int i=0; i<4; i++)
{
myLabels[i]->setText( "test" );
}
}
bool app::myFunc()
{
for (int i=0; i<4; i++)
{
myLabels[i]->setText( "test" );
}
}
To copy to clipboard, switch view to plain text mode
And myFunc() causes segmentation fault. Any idea why?
When I do:
ui->label1->setText( "test" );
ui->label1->setText( "test" );
To copy to clipboard, switch view to plain text mode
Everything is OK.
thanks in advance
best regards
Tomasz
Bookmarks