• 7039阅读
  • 6回复

初级问题,关于 C++ GUI Qt4编程一书中2.3节的一个疑问 [复制链接]

上一主题 下一主题
离线thinkbad
 

只看楼主 倒序阅读 楼主  发表于: 2009-11-20
初学QT,看C++ GUI Qt4编程 2.3节通过正则实现输入定位单元格的功能
gotocelldialog.h中声明的槽函数
  1. private slots:
  2.     void on_lineEdit_textChanged()


在构造函数中并没有与任何信号与此信号槽连接,那么是如何生效的呢?
  1.    QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
  2.     lineEdit->setValidator(new QRegExpValidator(regExp, this));
  3.     connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
  4.     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
离线dbzhang800

只看该作者 1楼 发表于: 2009-11-20
看书不认真,答案就是这一节,自己找
离线thinkbad

只看该作者 2楼 发表于: 2009-11-20
不能怪我,我看的是某中文word版本。。。确实少翻译了些内容,在英文版 我找到了答案
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()));

我就说嘛 按我昨天的理解 构造函数里应该有上面这句的 我加上了 也没错
离线rqzrqh

只看该作者 3楼 发表于: 2009-11-20
相关文档。 QT自动连接信号槽.rar (6 K) 下载次数:12
离线foxyz

只看该作者 4楼 发表于: 2009-11-20
你自己加上了就有错了!!!,一次信号发出,你的slots函数会调用两次
离线thinkbad

只看该作者 5楼 发表于: 2009-11-20
引用第4楼foxyz于2009-11-20 10:09发表的  :
你自己加上了就有错了!!!,一次信号发出,你的slots函数会调用两次

是我debug看 确实是触发了两次 昨天还比较纳闷呢 今天明白了
离线thinkbad

只看该作者 6楼 发表于: 2009-11-20
引用第3楼rqzrqh于2009-11-20 10:09发表的  :
相关文档。 [图片]


感谢 文档说的很清晰
快速回复
限100 字节
 
上一个 下一个