当前位置: 技术问答>linux和unix
QT编程疑问
来源: 互联网 发布时间:2016-06-28
本文导语: 本帖最后由 proudboy_linux 于 2009-09-02 10:24:31 编辑 在《C++GUI Programming with QT4,second Edition》的Rapid Dialog Design的一节中有一个例子: #ifndef GOTOCELLDIALOG_H #define GOTOCELLDIALOG_H #include #include "ui_gotocelldialog.h" class GoTo...
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include
#include "ui_gotocelldialog.h"
class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
{
Q_OBJECT
public:
GoToCellDialog(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
};
#endif
CPP文件:
#include
#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()));
}
void GoToCellDialog::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
书上解释说setupUi()函数会自动将lineEdit的textChanged信号与槽函数on_lineEdit_textChanged();连接,要求槽函数名字一定是on_objectName_signalName()这种格式。如果我不想使用这种格式命名,而是自己写一个slot,自己在构造函数中去connect,该如何做??
我试过下面这种方法,但是不行,okButton始终是unable的。
#include
#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()));
connect(lineEdit, SIGNAL(textChanged(const QString &str)), this, SLOT(dotextChanged())); //我加的
}
void GoToCellDialog::dotextChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
|
恭喜你!偶最近也在学Qt,thank U!
|
不错,自学能力很强,呵呵