QLabel 2D Array
Verfasst: 30. Juni 2009 16:06
Hi,
in einem Programm benötige ich ein dynamisches 2D Array mit QLabel's. Das ganze sieht in etwa so aus:
Leider erhalte ich an der Stelle (pArray[j] = laField;) die folgende Fehlermeldung:
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'QLabel *' (or there is no acceptable conversion)
could be 'QLabel &QLabel::operator =(const QLabel &)'
Darauf habe ich mir eine Klasse von QLabel abgeleitet und dieser wie folgt einen Copy Konstruktor hinzugefügt:
Wenn ich jetzt anstelle von QLabel MyLabe verwende, kann ich den zuvor gezeigten Code verwenden, aber mit pArray[0][0].text() erhalte ich keinen Wert. Wo ist mein Fehler?
in einem Programm benötige ich ein dynamisches 2D Array mit QLabel's. Das ganze sieht in etwa so aus:
Code: Alles auswählen
QLabel** pArray;
pArray = new QLabel*[row];
for(int i = 0; i < row; i++)
{
pArray[i] = new QLabel[col];
for(int j = 0; j < col; j++)
{
QLabel* laField = new QLabel(this);
laField->setText("ABC");
pArray[i][j] = laField;
}
}
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'QLabel *' (or there is no acceptable conversion)
could be 'QLabel &QLabel::operator =(const QLabel &)'
Darauf habe ich mir eine Klasse von QLabel abgeleitet und dieser wie folgt einen Copy Konstruktor hinzugefügt:
Code: Alles auswählen
class MyLabel : public QLabel{
Q_OBJECT
public:
MyLabel(QWidget *parent = 0); // Default Konstruktor
MyLabel &operator = (const MyLabel &c){return *this;}; // Copy Konstruktor
~MyLabel();
};