无法从摘要中调用按钮信号 class

cannot call button signal from abstract class

我想在点击按钮时调用一个函数。按钮的实现是抽象的 class。但是当我编译时出现这个错误。

这是我的基础.h文件class

#ifndef HOME_H
#define HOME_H
#include<QGraphicsScene>
#include <QGraphicsScene>
#include<QPushButton>

class home
{
  Q_OBJECT
public:
  home();

  virtual void set_home_background()=0 ;
  QGraphicsScene *scene3;
  QPushButton *button3;

private slots:
  virtual void startgame1();
};

#endif // HOME_H

这是基础class

#include "home.h"
#include<QGraphicsScene>
#include<QGraphicsProxyWidget>
#include "QMessageBox"

home::home()
{

}

void home::set_home_background()
{
  button3 = new QPushButton;
  QObject::connect(button3,SIGNAL(clicked()),this,SLOT(startgame1()));
  QGraphicsProxyWidget *proxy = this->scene3->addWidget(button3);
  button3->setAutoFillBackground(true);
  button3->setIcon(QIcon(":/Images/ng.png"));
  button3->setIconSize(QSize(131,41));
  proxy->setPos(130,430);
  scene3->addItem(proxy);
}

void home::startgame1()
{
  QMessageBox q;
  q.setText("");
  q.exec();
}

我遇到了这个错误

C:\Users\User\Documents\breakout_final\home.cpp:16: error: no matching function for call to 'QObject::connect(QPushButton*&, const char*, home*, const char*)' QObject::connect(button3,SIGNAL(clicked()),this,SLOT(startgame1()));

                                                                   ^

您的代码有一个错误:为了使用 Qt 信号和槽,您应该从 QObject 继承您的 class,Q_OBJECT 声明本身是不够的:

#include <QObject>

class home : public QObject
{
    Q_OBJECT
public:
    home();


    virtual void set_home_background()=0 ;
     QGraphicsScene *scene3;
     QPushButton *button3;

private slots:
    virtual void startgame1();    
};