Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt对话框接受和拒绝_Qt_Checkbox_Textbox_Dialog - Fatal编程技术网

Qt对话框接受和拒绝

Qt对话框接受和拒绝,qt,checkbox,textbox,dialog,Qt,Checkbox,Textbox,Dialog,我试图实现以下功能:当单击特定按钮时,会出现一个新对话框,用户必须在其中输入一些信息并选中/取消选中一些复选框。然后用户可以单击“确定”或“取消” 如果他单击“确定”,则检查他输入的信息是否正确。如果出现不正确的情况,对话框应再次出现并显示警告消息,用户应更正/重新输入信息。我希望存储用户输入的信息。因此,如果信息不正确,对话框不应“重置”到初始状态,而应保留用户输入的信息 如果用户单击“取消”,则会进一步使用一些标准值 我几乎找到了一个解决方案,但它不能正常工作。使用我的解决方案时:当我输入错

我试图实现以下功能:当单击特定按钮时,会出现一个新对话框,用户必须在其中输入一些信息并选中/取消选中一些复选框。然后用户可以单击“确定”或“取消”

如果他单击“确定”,则检查他输入的信息是否正确。如果出现不正确的情况,对话框应再次出现并显示警告消息,用户应更正/重新输入信息。我希望存储用户输入的信息。因此,如果信息不正确,对话框不应“重置”到初始状态,而应保留用户输入的信息

如果用户单击“取消”,则会进一步使用一些标准值

我几乎找到了一个解决方案,但它不能正常工作。使用我的解决方案时:当我输入错误的信息并单击“确定”时,将显示一条警告并存储该信息,我可以对其进行编辑。但是,如果我再次输入错误的信息并再次单击“确定”,则会接受错误的信息。请看下面我的代码

QDialog dialog(this);
QFormLayout form(&dialog);

form.addRow((new QLabel("Please enter the three questions for the P835 test. \n"
                        "Questions one and two will be permuted, \n "
                        "question three will not. Below each question enter \n"
                        "the rating scale starting with the best rating and \n"
                        "separate the ratings with a comma.")));
QList<QLineEdit *> fields;

    QLineEdit *lineEdit_Q1 = new QLineEdit(&dialog);
    lineEdit_Q1->setText("Bitte bewerten Sie die Signalqualität!");
    QString label_Q1 = QString("First question:");
    form.addRow(label_Q1, lineEdit_Q1);
    fields << lineEdit_Q1;

    QLineEdit *lineEdit_Q1_answer = new QLineEdit(&dialog);
    lineEdit_Q1_answer->setText("nicht verzerrt, leicht verzerrt, etwas verzerrt, ziemlich verzerrt, sehr verzerrt");
    QString label_Q1_answer = QString("Rating first question:");
    form.addRow(label_Q1_answer, lineEdit_Q1_answer);
    fields << lineEdit_Q1_answer;

QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
    form.addRow(&buttonBox);
    QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
    QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
    bool click = true;
    int code = dialog.exec();
    bool passed = true;
    while (click == true){
        passed = true;
        if (code == QDialog::Accepted) {
        // check if empty questions were entered
        if (lineEdit_Q1->text() == "" || lineEdit_Q2->text() == "" || lineEdit_Q3->text() == "") {
            QMessageBox msgBox;
            msgBox.setText("An error occured while entering questions for the P835 test");
            msgBox.setInformativeText("You can not enter empty questions! Please try again or click cancel to use the standard questions!");
            msgBox.setIcon(QMessageBox::Warning);
            msgBox.exec();
            passed = false;
            dialog.close();
            dialog.exec();
            break;
        }
        if (lineEdit_Q1_answer->text().split(",").size() != 5 || lineEdit_Q2_answer->text().split(",").size() != 5 || lineEdit_Q3_answer->text().split(",").size() != 5) {
            QMessageBox msgBox;
            msgBox.setText("An error occured while entering question ratings for the P835 test");
            msgBox.setInformativeText("You have to enter exactly 5 ratings for each question! Please try again or click cancel to use the standard ratings!");
            msgBox.setIcon(QMessageBox::Warning);
            msgBox.exec();
            passed = false;
            dialog.close();
            dialog.exec();
            break;
        }
        if (oneFileCheckBox->isChecked() && multipleFilesCheckBox->isChecked()) {
            QMessageBox msgBox;
            msgBox.setText("An error occured while setting up the P835 test...");
            msgBox.setInformativeText("You cannot check both boxes! Please select only one option for the files!");
            msgBox.setIcon(QMessageBox::Warning);
            msgBox.exec();
            passed = false;
            dialog.close();
            dialog.exec();
            break;
        }
        if (oneFileCheckBox->isChecked() == false && multipleFilesCheckBox->isChecked() == false) {
            QMessageBox msgBox;
            msgBox.setText("An error occured while setting up the P835 test...");
            msgBox.setInformativeText("You have to select one file option!");
            msgBox.setIcon(QMessageBox::Warning);
            msgBox.exec();
            passed = false;
            dialog.close();
            dialog.exec();
            break;
        }
        if (passed == true) {
            this->configMgr->setQuestions(lineEdit_Q1->text(), lineEdit_Q2->text(), lineEdit_Q3->text());
            this->configMgr->setAnswers(lineEdit_Q1_answer->text(), lineEdit_Q2_answer->text(), lineEdit_Q3_answer->text());
            if(oneFileCheckBox->isChecked() == true) {
                this->configMgr->fileOption = 0;
            }
            if(multipleFilesCheckBox->isChecked() == true) {
                this->configMgr->fileOption = 1;
            }
            QMessageBox msgBox;
            msgBox.setText("Success!");
            msgBox.setInformativeText("The questions and the question ratings have been set successfully!");
            msgBox.setIcon(QMessageBox::Information);
            msgBox.exec();
            dialog.close();
            click = false;
        }
        if (code == QDialog::Rejected) {
            this->configMgr->setQuestions(Q1_std, Q2_std, Q3_std);
            this->configMgr->setAnswers(Q1_std_answer, Q2_std_answer, Q3_std_answer);
            QMessageBox msgBox;
            msgBox.setText("Setting standard values...");
            msgBox.setInformativeText("Standard questions and ratings will be set. Click on the P835 button again to set questions and ratings manually!");
            msgBox.setIcon(QMessageBox::Information);
            msgBox.exec();
            dialog.close();
            click = false;
        }
        }
        if (code == QDialog::Rejected) {
            this->configMgr->setQuestions(Q1_std, Q2_std, Q3_std);
            this->configMgr->setAnswers(Q1_std_answer, Q2_std_answer, Q3_std_answer);
            QMessageBox msgBox;
            msgBox.setText("Setting standard values...");
            msgBox.setInformativeText("Standard questions and ratings will be set. Click on the P835 button again to set questions and ratings manually!");
            msgBox.setIcon(QMessageBox::Information);
            msgBox.exec();
            dialog.close();
            click = false;
        }
    }
QDialog对话框(此对话框);
QFormLayout表单(&对话框);
form.addRow((新QLabel)(“请为P835测试输入三个问题。\n”
问题1和问题2将被替换,\n
“问题三不会。请在每个问题下方输入\n”
“以最佳评分开始的评分量表,以及\n”
“用逗号分隔收视率。”);
QList字段;
QLineEdit*lineEdit\u Q1=新的QLineEdit(&dialog);
lineEdit_Q1->setText(“bite bewerten Sie die Signalqualität!”);
QString label_Q1=QString(“第一个问题:”);
表格.addRow(标签为Q1,行编辑为Q1);
字段设置文本(“nicht-verzerrt、leicht-verzerrt、etwas-verzerrt、ziemlich-verzerrt、sehr-verzerrt”);
QString label_Q1_answer=QString(“评级第一个问题:”);
表格.addRow(标签为Q1答案,行编辑为Q1答案);
字段text()=“”| | lineEdit_Q2->text()=“”| | lineEdit_Q3->text()=“”){
QMessageBox-msgBox;
msgBox.setText(“为P835测试输入问题时出错”);
msgBox.setInformativeText(“您不能输入空问题!请重试或单击“取消”以使用标准问题!”);
设置图标(QMessageBox::警告);
msgBox.exec();
通过=错误;
dialog.close();
dialog.exec();
打破
}
如果(lineEdit_Q1_答案->text().split(“,”).size()!=5 | | lineEdit_Q2_答案->text().split(“,”).size()!=5 | | lineEdit_Q3_答案->text().split(“,”).size()!=5){
QMessageBox-msgBox;
msgBox.setText(“为P835测试输入问题评分时出错”);
msgBox.setInformativeText(“您必须为每个问题输入5个评分!请重试或单击“取消”以使用标准评分!”);
设置图标(QMessageBox::警告);
msgBox.exec();
通过=错误;
dialog.close();
dialog.exec();
打破
}
如果(oneFileCheckBox->isChecked()&&multiplefilecheckbox->isChecked()){
QMessageBox-msgBox;
msgBox.setText(“设置P835测试时出错…”);
msgBox.setInformativeText(“不能同时选中两个框!请仅为文件选择一个选项!”);
设置图标(QMessageBox::警告);
msgBox.exec();
通过=错误;
dialog.close();
dialog.exec();
打破
}
if(oneFileCheckBox->isChecked()==false&&multiplefilecheckbox->isChecked()==false){
QMessageBox-msgBox;
msgBox.setText(“设置P835测试时出错…”);
setInformativeText(“您必须选择一个文件选项!”);
设置图标(QMessageBox::警告);
msgBox.exec();
通过=错误;
dialog.close();
dialog.exec();
打破
}
如果(通过==true){
此->配置管理器->设置问题(lineEdit_Q1->text(),lineEdit_Q2->text(),lineEdit_Q3->text());
此->configMgr->setAnswers(lineEdit_Q1_answer->text(),lineEdit_Q2_answer->text(),lineEdit_Q3_answer->text());
如果(oneFileCheckBox->isChecked()==true){
此->配置管理器->文件选项=0;
}
如果(MultipleFileCheckBox->isChecked()==true){
此->配置管理器->文件选项=1;
}
QMessageBox-msgBox;
msgBox.setText(“成功!”);
msgBox.setInformativeText(“问题和问题评级已成功设置!”);
setIcon(QMessageBox::信息);
msgBox.exec();
dialog.close();
单击=false;
}
如果(代码==QDialog::已拒绝){
这->配置管理->设置问题(Q1\U标准、Q2\U标准、Q3\U标准);
此->配置管理器->设置应答(Q1\U标准应答、Q2\U标准应答、Q3\U标准应答);
QMessageBox-msgBox;
msgBox.setText(“设置标准值…”);
msgBox.setInformativeText(“将设置标准问题和评分。再次单击P835按钮可手动设置问题和评分!”);
setIcon(QMessageBox::信息);
msgBox.exec();
dialog.close();
单击=false;
}
}
如果(代码==QDialog::已拒绝){
这->配置管理->设置问题(Q1\U标准、Q2\U标准、Q3\U标准);
此->配置管理器->设置应答(Q1\U标准应答、Q2\U标准应答、Q3\U标准应答);
QMessageBox-msgBox;
msgBox.setText(“设置标准值…”);
msgBox.setInformativeText(“将设置标准问题和评分。再次单击P835按钮可手动设置问题和评分!”);
void DataSourceDlg::done(int r)
{
    if(QDialog::Accepted == r)  // ok was pressed
    {
        if(nodeLineEdit->text().size() > 3)   // validate the data somehow
        {
            QDialog::done(r);
            return;
        }
        else
        {
            statusBar->setText("Invalid data in text edit...try again...");
            return;
        }
    }
    else    // cancel, close or exc was pressed
    {
        QDialog::done(r);
        return;
    }
}
companyLabel = new QLabel(tr("&Company name:"));
companyLineEdit = new QLineEdit;
companyLabel->setBuddy(companyLineEdit);

emailLabel = new QLabel(tr("&Email address:"));
emailLineEdit = new QLineEdit;
emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
emailLabel->setBuddy(emailLineEdit);

postalLabel = new QLabel(tr("&Postal address:"));
postalLineEdit = new QLineEdit;
postalLabel->setBuddy(postalLineEdit);

registerField("details.company*", companyLineEdit);
registerField("details.email*", emailLineEdit);
registerField("details.postal*", postalLineEdit);
    validatorLineEdit->setValidator(new QIntValidator(
        validatorLineEdit));

    validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
        999.0, 2, validatorLineEdit));
    inputMaskLineEdit->setInputMask("");

    inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");

    inputMaskLineEdit->setInputMask("0000-00-00");
    inputMaskLineEdit->setText("00000000");
    inputMaskLineEdit->setCursorPosition(0);

    inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
// regexp: optional '-' followed by between 1 and 3 digits
QRegExp rx("-?\\d{1,3}");
QValidator *validator = new QRegExpValidator(rx, this);

QLineEdit *edit = new QLineEdit(this);
edit->setValidator(validator);