我有问题。编译时一切都很棒,但插槽不起作用。应用程序启动后,它会输出QObject::connect: No such signal CMatrix::ReadyToDraw(ww)
。我测试了它,插槽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();
}
答案 0 :(得分:1)
您的信号签名是
ReadyToDraw(CMatrix *)
不
ReadyToDraw(ww)
因为connect()需要类型,而不是变量的名称。
将连接线更改为:
QObject::connect(ww,SIGNAL(ReadyToDraw(CMatrix *)),&w,SLOT(DrawFunction(CMatrix *)));