QObject::connect:没有这样的信号(类名)(信号名)(atribure)

QObject::connect: No such signal(classname)(signalname)(atribure)

我有问题。当我编译时一切都很好,但插槽不起作用。应用程序启动后,输出QObject::connect: No such signal CMatrix::ReadyToDraw(ww)。我测试了一下,slot DrawFunction() 不工作。由于分段错误,我无法调试。

header.h

class CMatrix:public QObject
{
    Q_OBJECT
public:
    int **m_pMatrix;
    const short int m_size=4;
public:
    CMatrix();
    bool checkFields();
    void setField();
signals:
    void ReadyToDraw(CMatrix *ww);
public slots:
    void MoveDown();
    void MoveTop();
    void MoveLeft();
    void MoveRight();
};
class MainWindow : public QWidget
{
    Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
    void DrawFunction(CMatrix *A);
public:
    QPushButton* butTop;
    QList<QLabel*> lblList;
};

main.cpp

#include "header.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    CMatrix *ww=new CMatrix;
    QObject::connect(w.butTop,SIGNAL(clicked()),ww,SLOT(MoveTop()));
    QObject::connect(ww,SIGNAL(ReadyToDraw(ww)),&w,SLOT(DrawFunction(ww)));
    w.show();


    return a.exec();
}

您的信号签名是

ReadyToDraw(CMatrix *)

没有

ReadyToDraw(ww)

因为 connect() 需要类型,而不是变量名。

所以将您的连接线更改为:

QObject::connect(ww,SIGNAL(ReadyToDraw(CMatrix *)),&w,SLOT(DrawFunction(CMatrix *)));