如何检查两个QLineEdit如果它们不是空的

Lio*_*ing 1 c++ qt qt5

我有三个控件,两个QTextLine和一个QPushButton.

启动程序时,将禁用添加按钮,并且必须为两个QTextLine非空,才能启用添加按钮.

我有以下代码,但它不能正常工作:

void Question_Answer::on_newQuestion_txt_textChanged(const QString &arg1)
{
    if(arg1.isEmpty())
    {
        ui->addNewQuestion_btn->setEnabled(false);
    }
    else
    {
        ui->addNewQuestion_btn->setEnabled(true);
    }
}

void Question_Answer::on_newAnswer_txt_textChanged(const QString &arg1)
{
    if(ui->newAnswer_txt->text().isEmpty())
    {
        ui->addNewQuestion_btn->setEnabled(false);
    }
    else
    {
        ui->addNewQuestion_btn->setEnabled(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,如何检查两者是否为QTextLine空,以及如果其中任何一个为空,将禁用添加按钮.

Lah*_*ima 6

只需连接一个插槽即可处理textChanged两者的信号LineEdits

void Question_Answer::onTextChanged(const QString &arg1){
    if(ui->newAnswer_txt->text().isEmpty() || ui->newQuestion_txt->text().isEmpty()){
        ui->addNewQuestion_btn->setEnabled(false);
    }else{
        ui->addNewQuestion_btn->setEnabled(true);
    }
}
Run Code Online (Sandbox Code Playgroud)