Reputation: 79
I'm pretty new to Qt and I came across a problem I don't find a fix for.
So my problem is as follows:
I try to generate a QtLabel
inside a class and display it in my mainWindow
.
class Hexagon
{
public:
QPolygon polygon;
QLabel *cellText = new QLabel(this);
Hexagon(int startX, int startY, int length, int row, int cell, char letters[26])
{
polygon <<
QPoint(startX, startY)
<<
QPoint(startX+length*qCos(qDegreesToRadians(30.0)), startY-length*qSin(qDegreesToRadians(30.0)))
<<
QPoint(startX+2*length*qCos(qDegreesToRadians(30.0)), startY)
<<
QPoint(startX+2*length*qCos(qDegreesToRadians(30.0)), startY+length)
<<
QPoint(startX+length*qCos(qDegreesToRadians(30.0)), startY+length+length*qSin(qDegreesToRadians(30.0)))
<<
QPoint(startX, startY+length);
cellText->setText(QString(QChar(letters[row])) + QString(QChar(letters[cell])));
cellText->setGeometry(startX + 35, startY + 10, 40, 20);
cellText->show();
}
};
So there is my Hexagon class that creates a hexagon formed polygon that can be drawn later. Now I try to add some QtLabel for each Cell (Hexagon) I have.
But I run into an error:
widget.cpp:28: Fehler: no matching constructor for initialization of 'QLabel'
How can I fix this error and generate my Label inside my Class and extend the mainWindow with it?
Upvotes: 0
Views: 282
Reputation: 48297
the reason of the error is because you are using the QLabel constructor wrong
there is only
QLabel(QWidget *, Qt::WindowFlags )
QLabel(const QString &, QWidget *, Qt::WindowFlags )
and no
QLabel(Hexagon*)
thus, the line with
QLabel *cellText = new QLabel(this);
is not valid because of this
Upvotes: 1