This question already has an answer here:
- C++ Qt signal and slot not firing 3 answers
I have been working on learning C++ and Qt4 recently, but I have hit a stumbling block.
I have the following class and implementation:
class Window : public QWidget
{
public:
Window();
public slots:
void run();
private:
//...
};
and
Window::Window()
{
//...
connect(runBtn,SIGNAL(clicked()),this,SLOT(run()));
//...
}
Window::run()
{
//...
}
However, when I attempt to build and run it, although it builds just fine, it immediately exits out with the message
Object::connect: No such slot QWidget::run()
Unless I did something wrong, Qt does not seem to be recognizing the slot run()
Could anyone please help?
Update:
The code is now:
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
public slots:
void run();
private:
//...
};
and
Window::Window(QWidget *parent) : QWidget(parent)
{
//...
connect(runBtn,SIGNAL(clicked()),this,SLOT(run()));
//...
}
Window::run()
{
//...
}
The program still "unexpectedly finished", but no longer tell me that there is no such thing as QWidget::run()