This question already has answers here:
C++ Qt signal 以及 slot not firing
(3 answers)
Closed 8 years ago.
我最近一直在学习C++和Qt4,但我打着一个 st脚石。
我有以下类别和执行:
class Window : public QWidget
{
public:
Window();
public slots:
void run();
private:
//...
};
以及
Window::Window()
{
//...
connect(runBtn,SIGNAL(clicked()),this,SLOT(run()));
//...
}
Window::run()
{
//...
}
However, when I attempt to build 以及 run it, although it builds just fine, it immediately exits out with the message
Object::connect: No such slot QWidget::run()
除非我错了, 标记似乎并不承认<代码>run()。
谁能提供帮助?
<>Update:
现行法典是:
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
public slots:
void run();
private:
//...
};
以及
Window::Window(QWidget *parent) : QWidget(parent)
{
//...
connect(runBtn,SIGNAL(clicked()),this,SLOT(run()));
//...
}
Window::run()
{
//...
}
该方案仍然“未具体完成”,但不再告诉我,没有像<代码”这样的东西。 QWidget:run()