Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.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++ QMessageBox带有一个";“不要再显示此内容”;复选框_C++_Qt_Checkbox_Qmessagebox - Fatal编程技术网

C++ QMessageBox带有一个";“不要再显示此内容”;复选框

C++ QMessageBox带有一个";“不要再显示此内容”;复选框,c++,qt,checkbox,qmessagebox,C++,Qt,Checkbox,Qmessagebox,如何显示下面带有“不再显示”复选框的消息框 我想象的事情是这样的: Qt5.2增加了将QCheckBox添加到QMessageBox的可能性。看看 下面是一些演示代码 if (this->showMsgBox) { QCheckBox *cb = new QCheckBox("Okay I understand"); QMessageBox msgbox; msgbox.setText("Am I nerve-wrecking?"); msgbox.setI

如何显示下面带有“不再显示”复选框的消息框

我想象的事情是这样的:


Qt5.2增加了将
QCheckBox
添加到
QMessageBox
的可能性。看看

下面是一些演示代码

if (this->showMsgBox) {
    QCheckBox *cb = new QCheckBox("Okay I understand");
    QMessageBox msgbox;
    msgbox.setText("Am I nerve-wrecking?");
    msgbox.setIcon(QMessageBox::Icon::Question);
    msgbox.addButton(QMessageBox::Ok);
    msgbox.addButton(QMessageBox::Cancel);
    msgbox.setDefaultButton(QMessageBox::Cancel);
    msgbox.setCheckBox(cb);

    QObject::connect(cb, &QCheckBox::stateChanged, [this](int state){
        if (static_cast<Qt::CheckState>(state) == Qt::CheckState::Checked) {
            this->showMsgBox = false;
        }
    });

    msgbox.exec();
}
if(此->showMsgBox){
QCheckBox*cb=新的QCheckBox(“好的,我明白”);
QMessageBox-msgbox;
msgbox.setText(“我神经崩溃了吗?”);
setIcon(QMessageBox::Icon::Question);
添加按钮(QMessageBox::Ok);
msgbox.addButton(QMessageBox::Cancel);
msgbox.setDefaultButton(QMessageBox::Cancel);
msgbox.setCheckBox(cb);
连接(cb,&QCheckBox::stateChanged,[this](int状态){
if(static_cast(state)==Qt::CheckState::Checked){
此->showMsgBox=false;
}
});
msgbox.exec();
}

内置了此功能。我的答案对您有用吗?如果是,请随意接受它。除非
msgbox.exec()connect
语句之后调用code>
exec()
是一个阻塞调用,
stateChanged
信号以这种方式无效。只是用一个小的演示应用程序尝试了一下。当然你是对的。实际上他没有运行代码。愚蠢的我。非常感谢。很抱歉问这个愚蠢的问题,ShowMsgBox到底是什么?它是我使用的测试类的一个布尔成员变量。在Qt5上获取
错误:在非成员函数中无效地使用了'this',并且必须更改为
QObject::connect(cb,&QCheckBox::stateChanged,[=](const int&state){
-一个C++11 lambda表达式。