Qt - 没有匹配函数来调用连接
Qt - No matching function to call connect
我正在尝试在Qt中执行经典的连接,我已经做了一千次。但是由于我不知道的某种原因,我现在不能:我收到错误
error: no matching function for call to 'gameView::connect(QComboBox*&, const char*, gameLogic*&, const char*)'
connect(_dropdown, SIGNAL(activated(int)), _model, SLOT(resize(int)));
^
我的代码如下:(游戏视图.h)
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QComboBox>
#include <QVector>
#include <QTime>
#include "gamelogic.h"
class gameView : public QWidget
{
Q_OBJECT
public:
...
QComboBox*_dropdown;
...
gameLogic* _model;
...
explicit gameView(QWidget *parent = 0);
~gameView();
};
#endif // MAINWINDOW_H
(游戏视图.cpp)
#include "gameview.h"
gameView::gameView(QWidget *parent) :
QWidget(parent)
{
_model = new gameLogic();
...
_dropdown = new QComboBox();
...
_dropdown->addItem("4");
_dropdown->addItem("6");
_dropdown->addItem("8");
connect(_dropdown, SIGNAL(activated(int)), _model, SLOT(resize(int))); //error here
...
}
(游戏逻辑.h)
#ifndef GAMELOGIC_H
#define GAMELOGIC_H
#include <QVector>
#include <QTimer>
class gameLogic
{
Q_OBJECT
public:
gameLogic();
...
public slots:
void resize(int newn);
};
#endif // GAMELOGIC_H
请帮忙!
你的gameLogic
类应该继承QObject,否则Qt信号/时隙机制将不起作用。尝试将class gameLogic
更改为class gameLogic : public QObject
显然仅仅添加Q_OBJECT
是不够的。将gameLogic
变成class gameLogic : public QObject
后,连接工作。
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 返回指向对象的指针的函数调用是否为 prvalue?
- C++ 如何重载 [] 运算符并进行函数调用
- 代码的效率. 转到和函数调用
- 是同一作用域的函数部分中的函数调用
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 类型擦除的std::function与虚拟函数调用的开销