简体   繁体   中英

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. this is what i am trying in the header file :

public:
    Compteur(QWidget *parent = nullptr , int variable= 5);

and in the cpp file :

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 :

include "compteur.h"

include

Compteur::Compteur(QWidget *parent , int valI) : QLabel(parent)
{

}

in your cpp file the parameters should be like this

Compteur::Compteur(QWidget *parent, int variable) : QLabel(parent)
{

}

Just remove or comment

ifndef COMPTEUR_H

// heder file here

endif // COMPTEUR_H

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM