this code:
...
*(this
->labels
) = new QLabel[10];
for(int i=0; i<=9; i++)
{
labels
[i
] = new QLabel(tr
("TEST"));
labels[i]->setFrameStyle(1);
this->layoutTab1->addWidget(this->labels[i]);
}
QLabel **labels;
...
*(this->labels) = new QLabel[10];
for(int i=0; i<=9; i++)
{
labels[i] = new QLabel(tr("TEST"));
labels[i]->setFrameStyle(1);
labels[i]->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
this->layoutTab1->addWidget(this->labels[i]);
}
To copy to clipboard, switch view to plain text mode
is very problematic.
It seems you are probably coming from a C background, but don't understand what an object is.
Put all your labels in a container, a QList or QVector.
//in the class header make a member
QList<QLabel*> m_labels;
...
//in the implementation then you do:
for(int i=0; i<=9; i++)
{
QLabel *pLabel
= new QLabel(this,tr
("TEST"));
//if you don't give the label a parent, you have to make sure to delete it your self! pLabel ->setFrameStyle(1);
this->layoutTab1->addWidget(pLabel );
m_lables.push_back(pLabel);
}
...
//To access label you do:
m_labels.at(index)->setText("some text");
//in the class header make a member
QList<QLabel*> m_labels;
...
//in the implementation then you do:
for(int i=0; i<=9; i++)
{
QLabel *pLabel = new QLabel(this,tr("TEST")); //if you don't give the label a parent, you have to make sure to delete it your self!
pLabel ->setFrameStyle(1);
pLabel ->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
this->layoutTab1->addWidget(pLabel );
m_lables.push_back(pLabel);
}
...
//To access label you do:
m_labels.at(index)->setText("some text");
To copy to clipboard, switch view to plain text mode
Also, you have made your pointer local in the method - so you wont have access to them once the method is out of scope.
So in my example the list should be a member.
Bookmarks