无法从抽象类调用按钮信号
cannot call button signal from abstract class
我想在单击按钮时调用功能。该按钮的实现是在抽象类中。但是当我编译时,我会遇到此错误。
这是我的.h文件
#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
这是基类
#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: user user documents breakout_final home.cpp:16:错误:无匹配 呼叫'qobject :: connect(qpushbutton*&amp;,const char*, 家*,const char*)' qObject ::连接(button 3,signal(clicked()),slot(startgame1()));
^
您在代码中有一个错误:为了使用QT信号和插槽,您应该从qobject继承类,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();
};
相关文章:
- Qt VTK交互风格的信号到小部件
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 问:如何使用C++中的按钮从窗口打开窗口
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 将QPush按钮::单击信号到插槽时出错
- 按钮组上的 Qt 信号未连接
- QT按钮组和可检查的按钮:如何将切换信号与整数和布尔值连接?
- 如何在按下按钮时捕获捆绑的 GDB 发出的信号"stop"?
- 无法从抽象类调用按钮信号
- QT qml 按钮发出信号单击,尽管已禁用
- 右键单击按钮GTKMM-3.0的信号
- C++中按钮的简单信号
- QFileDialog中的后退和前进按钮没有信号
- 从C++代码发出 BB 级联按钮的"clicked()"信号
- (Qt)从按钮的QButtonGroup创建信号
- 在Visual Studio中按下"停止调试"按钮时拦截信号/事件
- GTKmm:程序崩溃时,试图连接按钮点击信号
- Qt不需要的双执行按钮按下的信号
- Qt如何使一个按钮响应时,插槽连接到它的click()信号正在运行
- 处理来自动态按钮阵列的信号