Important: Please read the Qt Code of Conduct -

contructor problem inheritance QPushbutton

  • Hello,

    I did the following code:

    #include <QtWidgets/QPushButton>
    class cell : public QPushButton {
    int state = 0;
    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;


    #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.


  • @xcalzada

    is giving an error I cannot detect why

    You should always quote error messages!

    You have written constructor

    cell::cell(QWidget *parent)

    only. What about the other QPushButton constructor overloads, like

    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