Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

contructor problem inheritance QPushbutton



  • Hello,

    I did the following code:

    //CELL HEADER
    #include <QtWidgets/QPushButton>
    class cell : public QPushButton {
    private:
    int state = 0;
    public:
    cell(QWidget *parent = 0);
    int getState();
    void setState(int);
    };

    //CELL CPP
    #include "cell.h"
    cell::cell(QWidget *parent)
    :QPushButton(parent) {
    }
    int cell::getState() {
    return this->state;
    }
    void cell::setState(int state) {
    this->state = state;
    }

    //MAIN.CPP

    #include <QtWidgets/QApplication>
    #include "minesweeper.h"

    int main(int argc, char *argv[])
    {
    cell *a = new cell("some");
    QPushButton *b = new QPushButton("test1");
    }

    The first line "cell *a = new cell("some");" is giving an error I cannot detect why. seems exactly like the second one.

    Best



  • @xcalzada

    is giving an error I cannot detect why

    You should always quote error messages!

    You have written constructor

    cell::cell(QWidget *parent)
    :QPushButton(parent) 
    

    only. What about the other QPushButton constructor overloads, like https://doc.qt.io/qt-5/qpushbutton.html#QPushButton-1

    QPushButton::QPushButton(const QString &text, QWidget *parent = nullptr)
    

    which is the one you want to override in cell for for your cell *a = new cell("some") ?


Log in to reply