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_Windows 7_Checkbox_Callback_Visual Studio 2005 - Fatal编程技术网

Qt复选框状态已更改事件处理程序

Qt复选框状态已更改事件处理程序,qt,windows-7,checkbox,callback,visual-studio-2005,Qt,Windows 7,Checkbox,Callback,Visual Studio 2005,在我的Qt应用程序中,我想使用复选框在切换到未选中时执行a,在切换到选中时执行B。该复选框连接到foo(int) 当健全性检查失败时(例如,某些变量得到无效值)会出现问题,我只想显示错误消息并保持所有内容不变。所以我再次切换复选框,将其还原到原来的位置。但是这个动作似乎会再次触发回调函数foo(int),这会把一切都搞糟。我不想在这种情况下触发回调。我该怎么办?还是有更好的办法?请参阅下面的伪代码 void foo(int checkState) { if (checkState == Qt

在我的Qt应用程序中,我想使用复选框在切换到未选中时执行a,在切换到选中时执行B。该复选框连接到foo(int)

当健全性检查失败时(例如,某些变量得到无效值)会出现问题,我只想显示错误消息并保持所有内容不变。所以我再次切换复选框,将其还原到原来的位置。但是这个动作似乎会再次触发回调函数foo(int),这会把一切都搞糟。我不想在这种情况下触发回调。我该怎么办?还是有更好的办法?请参阅下面的伪代码

void foo(int checkState)
{
  if (checkState == Qt::Unchecked) {
    if (!passSanityCheck()) {
      // show error message
      checkBoxHandle->toggle();
      return;
    }

    // do A when it's unchecked
  }
  else {
    if (!passSanityCheck()) {
      // show error message
      checkBoxHandle->toggle();
      return;
    }

    // do B when it's checked
  }
  return;
}
将信号连接到插槽:

QCheckBox *cb = new QCheckBox(this);
connect(cb, SIGNAL(clicked(bool)), this, SLOT(toggled(bool)));
如果调用
setDown()
setChecked()
toggle()
,则不会发出此信号

QCheckBox *cb = new QCheckBox(this);
connect(cb, SIGNAL(clicked(bool)), this, SLOT(toggled(bool)));