繁体   English   中英

Qt-没有匹配函数可以调用connect

[英]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)));
                                                                         ^

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

(gameview.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
... 
}

(gamelogic.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是不够的。 gameLogicclass gameLogic : public QObject ,connect可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM