I am using Qt 4.6.2 and I am reading the book "C++ GUI Programming with Qt 4" the first Edition.
In the book, they said that
In the constructor, we call setupUi() to initialize the form. Thanks to multiple inheritance, we can access Ui::GoToCellDialog's members directly. After creating the user interface, setupUi() will also automatically connect any slots that follow the naming convention on_objectName_signalName() to the corresponding objectName's signalName() signal. In our example, this means that setupUi() will establish the following signalslot connection:
connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(on_lineEdit_textChanged()));
However, it didn't work unless I wrote the connect manually. Is that changed?
my header file
PHP Code:
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include <QDialog>
#include "ui_gotocelldialog.h"
class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
{
Q_OBJECT
public:
GoToCellDialog(QWidget *parent = 0);
private slots:
void on_lineEdit_textChange();
};
#endif // GOTOCELLDIALOG_H
my cpp file
PHP Code:
#include <QtGui>
#include "gotocelldialog.h"
GoToCellDialog::GoToCellDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp, this));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
//unless I wrote the following connect manually, the okButton would be never enabled.
connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(on_lineEdit_textChange()));
}
void GoToCellDialog::on_lineEdit_textChange()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
and the main file:
PHP Code:
#include <QApplication>
//#include <QDialog>
//#include <ui_gotocelldialog.h>
#include "gotocelldialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//Ui::GoToCellDialog ui;
//QDialog *dialog = new QDialog;
//ui.setupUi(dialog);
//dialog->show();
GoToCellDialog *dialog = new GoToCellDialog;
dialog->show();
return app.exec();
}
Anyone help is appreciated.