[英]Qt - No matching function to call connect
I'm trying to perform a classic connect in Qt, which I have done like a thousand times. 我正在尝试在Qt中执行经典连接,而我已经完成了上千次。 But for some reason unknown to me, I cant right now: I get the error 但是由于某种未知的原因,我现在无法:我得到了错误
error: no matching function for call to 'gameView::connect(QComboBox*&, const char*, gameLogic*&, const char*)'
connect(_dropdown, SIGNAL(activated(int)), _model, SLOT(resize(int)));
^
My code is as follows: (gameview.h) 我的代码如下:(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) (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) (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
Please help! 请帮忙!
Your gameLogic
class should inherit QObject, or the Qt signal/slot mechanism will not work. 您的gameLogic
类应该继承QObject,否则Qt信号/插槽机制将无法正常工作。 Try to change class gameLogic
to class gameLogic : public QObject
尝试将class gameLogic
更改为class gameLogic : public QObject
Apparently just adding Q_OBJECT
is not enough. 显然,仅添加Q_OBJECT
是不够的。 After making gameLogic
into class gameLogic : public QObject
, connect works. 将gameLogic
为class gameLogic : public QObject
,connect可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.