c++ - Qt - 没有匹配的功能来调用连接

标签 c++ qt

我正在尝试在 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)));
                                                                         ^

我的代码如下: (gameview.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

(游戏 View .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

关于c++ - Qt - 没有匹配的功能来调用连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37643691/

相关文章:

c++ - 将字符串作为二进制写入/读取到随机访问的文件中

c++ - Objective-C 和 Swift 之间的委托(delegate)问题

c++ - 带有函数回调的可变数量的参数(va_list)?

c++ - 图编辑框架

c++ - Qt 捕捉按下的键

c++ - 如何在 Linux 中获取 C/C++ 中的用户名?

c++ - (const char*)++ 还是 (const char)++?

c++ - QtWebkit是否需要从需要登录的网站获取数据?

c++ - 创建自定义 QT 库

c++ - QString解析系统变量