joshy198
22nd September 2012, 19:25
Constructor:
in mainwindow.h
...
private:
myLabel *l;
.....
in mainwindow.cpp
...
QString s = "l"+QString::number(i+1)+".png";
l = new myLabel();
l->setBackgroundRole(QPalette::Dark);
l->setAutoFillBackground(true);
image = new QImage(s);//Muss im debug-Ordner sein!!!
l->setPixmap(QPixmap::fromImage(*image));
l->setMaximumHeight(image->height());
l->setMaximumWidth(image->width());
l->setInfo(i+1);
...
--------------------------------------------------------------------
myLabel.h
#ifndef MYLABEL_H
#define MYLABEL_H
class myLabel : public QLabel
{
Q_OBJECT
public:
myLabel( const QString & text, QWidget * parent = 0 );
~myLabel(){}
void setInfo(int i);
int getInfo();
private:
int zahl;
signals:
void clicked();
public slots:
void slotClicked();
protected:
void mousePressEvent ( QMouseEvent * event ) ;
};
#endif
myLabel.cpp
#include "mylabel.h"
myLabel::myLabel( const QString & text, QWidget * parent = 0 )
:QLabel(parent)
{
connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) );
}
void myLabel::slotClicked()
{
qDebug()<<"Clicked";
}
void myLabel::mousePressEvent ( QMouseEvent * event )
{
emit clicked();
}
void myLabel::setInfo(int i)
{
zahl=i;
}
int myLabel::getInfo()
{
return zahl;
}
The Error is:
no matching function for call to 'myLabel::myLabel()'
candidates are: myLabel::myLabel(const QString&,QWidget*)
note: myLabel::myLabel(const myLabel&)
in mainwindow.h
...
private:
myLabel *l;
.....
in mainwindow.cpp
...
QString s = "l"+QString::number(i+1)+".png";
l = new myLabel();
l->setBackgroundRole(QPalette::Dark);
l->setAutoFillBackground(true);
image = new QImage(s);//Muss im debug-Ordner sein!!!
l->setPixmap(QPixmap::fromImage(*image));
l->setMaximumHeight(image->height());
l->setMaximumWidth(image->width());
l->setInfo(i+1);
...
--------------------------------------------------------------------
myLabel.h
#ifndef MYLABEL_H
#define MYLABEL_H
class myLabel : public QLabel
{
Q_OBJECT
public:
myLabel( const QString & text, QWidget * parent = 0 );
~myLabel(){}
void setInfo(int i);
int getInfo();
private:
int zahl;
signals:
void clicked();
public slots:
void slotClicked();
protected:
void mousePressEvent ( QMouseEvent * event ) ;
};
#endif
myLabel.cpp
#include "mylabel.h"
myLabel::myLabel( const QString & text, QWidget * parent = 0 )
:QLabel(parent)
{
connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) );
}
void myLabel::slotClicked()
{
qDebug()<<"Clicked";
}
void myLabel::mousePressEvent ( QMouseEvent * event )
{
emit clicked();
}
void myLabel::setInfo(int i)
{
zahl=i;
}
int myLabel::getInfo()
{
return zahl;
}
The Error is:
no matching function for call to 'myLabel::myLabel()'
candidates are: myLabel::myLabel(const QString&,QWidget*)
note: myLabel::myLabel(const myLabel&)