【发布时间】:2019-04-30 14:42:41
【问题描述】:
我刚开始阅读 QT,但我不太了解 SIGNAL SLOT 功能。 我有一个带有 2 QLineEdit 的表单,我想在单击按钮时将文本从第一个 QLineEdit 复制到第二个,但我不知道如何正确设置连接功能。
我尝试将 textChanged 函数与自身绑定,但结果是每次我按下一个字母时都会编辑文本,因为这是信号。
newForm::newForm() {
widget.setupUi(this);
connect(widget.nameEdit, SIGNAL(textChanged(const QString&)),
this, SLOT(textChanged(const QString&)));
connect(widget.pushMe, SIGNAL(pressed()),
this, SLOT(handleButton()));
}
void newForm::handleButton(){
}
我想我必须在 handleButton 函数中做点什么,但我不明白如何从第一行读取和复制文本,因为 text() 在 handleButton 中不起作用
【问题讨论】:
-
一种方法是直接访问小部件。第二种方法是在 newForm 类中设置一个 QString 变量,该变量在
textChanged()成员函数中设置。