Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. contructor problem inheritance QPushbutton
Forum Update on Monday, May 27th 2025

contructor problem inheritance QPushbutton

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 283 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xcalzada
    wrote on 12 Apr 2020, 15:43 last edited by
    #1

    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

    J 1 Reply Last reply 12 Apr 2020, 17:53
    0
    • X xcalzada
      12 Apr 2020, 15:43

      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

      J Offline
      J Offline
      JonB
      wrote on 12 Apr 2020, 17:53 last edited by JonB 4 Dec 2020, 17:54
      #2

      @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") ?

      1 Reply Last reply
      3

      1/2

      12 Apr 2020, 15:43

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved