qt中,比较QLineEdit的数据是否发生变化,如果变化则利用this->accept(),在按钮按下时将数据保存到文件,如果未发生变化则利用this->reject*()
时间: 2023-06-07 19:06:49 浏览: 54
在Qt中,可以使用QLineEdit的textChanged()信号来检测文本框内的内容是否发生变化。每当文本框内的文本发生变化时,textChanged()信号就会自动发出。可以将textChanged()信号与一个槽函数相连接,当文本框内的内容发生变化时,槽函数就会被自动调用。
在槽函数中,可以调用this->accept()或this->reject()函数来决定是否保存文本框内的内容到文件中。如果文本框内的内容发生变化,则调用this->accept()函数,否则调用this->reject()函数。
以下是一个示例代码:
//connect the QLineEdit's textChanged() signal to a slot
connect(ui->lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onTextChanged(const QString &)));
void YourWidget::onTextChanged(const QString &text)
{
//compare the new text with the old one
if(text != m_originalText)
{
//text has changed
this->accept(); //save changes
}
else
{
//text has not changed
this->reject(); //discard changes
}
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)