Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.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
C++ lineEdit中的Qt值和QCheckBox中的isChecked未按预期工作_C++_Qt - Fatal编程技术网

C++ lineEdit中的Qt值和QCheckBox中的isChecked未按预期工作

C++ lineEdit中的Qt值和QCheckBox中的isChecked未按预期工作,c++,qt,C++,Qt,当我按下submit按钮时,我试图弹出一个QMessageBox,该按钮工作正常,但是里面的消息取决于是否选中了某些复选框以及行编辑的值,例如: QApplication a(argc, argv); QMainWindow *w = new QMainWindow(); . . . QPushButton but_submit("Submit"); QMessageBox msg_submit; // The following will be so that we can get the

当我按下submit按钮时,我试图弹出一个
QMessageBox
,该按钮工作正常,但是里面的消息取决于是否选中了某些复选框以及行编辑的值,例如:

QApplication a(argc, argv);
QMainWindow *w = new QMainWindow();
.
.
.
QPushButton but_submit("Submit");
QMessageBox msg_submit;

// The following will be so that we can get the val of the GPA and then add it
// To the full message that will contain the info of person
QString submit_string = "Hello, here's the summary: \n";
submit_string += "Here\'s your value: " +  line_misc[0]->text() +  ".\n";
if (chk_art->isChecked())
    submit_string += "Art major!";
msg_submit.setText(submit_string);
.
. 
.
QObject::connect(&but_submit, SIGNAL(clicked()), &msg_submit, SLOT(exec()));

w->show();
return a.exec();
我已经定义或初始化了代码中没有的所有内容,当我运行代码时没有任何警告或错误,一切正常,所有内容都显示出来,但好像什么都没有连接

此时会出现消息框(
msg\u submit
),但消息已被删除

您好,这里是摘要:
这是您的值:

当我真的希望看到一个数字,或者如果我选中了复选框(
chk_art
),也希望看到艺术专业的评论,但不幸的是,我没有

我已经浏览了文档并尝试了一些变体,例如使用
spinBox
,使用属性函数
value()
来获取值并将其包装到
QString::number()
,但无论我将值更改为什么,这就像更改值时不调用
setValue
属性一样,或者插槽
valueChanged()
也不运行


我做错什么了吗?

单击事件发出后,您应该更新
提交字符串。
可以尝试使用lambda函数

QObject::connect(&but_submit, &QPushButton::clicked,
        [&line_misc, &chk_art](){
        QMessageBox msg_submit;
        QString submit_string = "Hello, here's the summary: \n";
        submit_string += "Here\'s your value: " + line_misc[0]->text() + ".\n";
        if (chk_art->isChecked())
            submit_string += "Art major!";
        msg_submit.setText(submit_string);
        msg_submit.exec();
    });

提供一个what is
line_misc
?@eyllansc line_misc是一个lineEdit数组,包含3个不同的数组,这些数组已初始化并添加到布局中。我应该强调一下,抱歉。不幸的是,我在尝试时出错,我还尝试切换&QPushButton::clicked。。。这里有一个错误——没有匹配的函数来调用'QObject::connect(QPushButton*,void(QAbstractButton::*)(),main(int,char**)::)'o单击,以及使用信号(clicked())我更新了代码。传递对lambda函数的引用
[&line\u misc,&chk\u art]
。顺便问一下,您使用的是c++11还是更高版本?