I tried a very simple program in QT. I created a dialog in QT designer with one push button. I want to have program, when I click on push button, I will get message box. I debugged the program. But, signal will not come to function OnClickedPushButton(bool) after clicking on push button. Where is a mistake? My code is looking like:
#include "qttest.h"
#include <QtGui>
#include <QMessageBox>
QTTest::QTTest(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(OnClickedPushButton()));
QPushButton *button = new QPushButton(this);
button->setText("ClcikMe");
button->setGeometry(QRect(QPoint(150, 50), QSize(85, 25)));
connect(button, SIGNAL(clicked()), this, SLOT(OnClickedPushButton()));
}
QTTest::~QTTest()
{
}
void QTTest::OnClickedPushButton()
{
QMessageBox::about(this, "Message", "You pushed button.");
}
I can build it, and I can launch it. But, debugger writes me in the constructor following messages:
QObject::connect: No such slot QTTest::OnClickedPushButton() in qttest.cpp:9
QObject::connect: (sender name: 'pushButton')
QObject::connect: (receiver name: 'QTTestClass')
QObject::connect: No such slot QTTest::OnClickedPushButton() in qttest.cpp:14
QObject::connect: (receiver name: 'QTTestClass')
I can see both buttons at the window. pushButton and button. But, if I will click on button the message will not come due to wrong slot mapping. Do you have any idea how to do it correctly?
OnClickedPushButtonis declared withinpublic:section. Declarepublic slots:beforeOnClickedPushButtondeclaration