[英]Passing default argument in constructor QT Creator ( inherited class )
i am trying to pass a default argument in a constructor but i can not figure out how it can be done since i am new to qt creator.我试图在构造函数中传递一个默认参数,但我不知道如何完成它,因为我是 qt creator 的新手。 this is what i am trying in the header file :这是我在头文件中尝试的内容:
public:
Compteur(QWidget *parent = nullptr , int variable= 5);
and in the cpp file :并在 cpp 文件中:
Compteur::Compteur(QWidget *parent = nullptr, int variable) : QLabel(parent)
{
}
the error i am getting is :我得到的错误是:
error: default argument given for parameter 1 of 'Compteur::Compteur(QWidget*, int)' [-fpermissive]
Compteur::Compteur(QWidget *parent = nullptr, int variable) : QLabel(parent)
The rest of the code : the header file :其余代码:头文件:
#ifndef COMPTEUR_H
#define COMPTEUR_H
#include <QtWidgets>
class Compteur : public QLabel
{
Q_OBJECT
QString texte;
int valeur;
int valeurInitiale;
public:
Compteur(QWidget *parent = nullptr , int valI = 5);
void setText(const QString &);
public slots:
void Decremente(){
}
void Reinitialise(){
}
};
#endif // COMPTEUR_H
^
and cpp file :和 cpp 文件:
Compteur::Compteur(QWidget *parent , int valI) : QLabel(parent)
{
}
in your cpp file the parameters should be like this在您的 cpp 文件中,参数应该是这样的
Compteur::Compteur(QWidget *parent, int variable) : QLabel(parent)
{
}
Just remove or comment只需删除或评论
ifndef COMPTEUR_H ifndef COMPTEUR_H
// heder file here //这里是heder文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.