【QT】触发信号时获取控件对象

snapshotBox = new CustomCheckBox [sys_info.max_cameras];
for (int i(0); i < sys_info.max_cameras && i < MAX_CAMERA; i++)
{
    (this->snapshotBox+i)->setText(QString("%1").arg(i + 1));
    ui->gridLayout_snapshot->addWidget(this->snapshotBox+i, i / 10, i % 10);
    connect(this->snapshotBox+i, SIGNAL(clicked(bool)), this, SLOT(onSnapshotCheckBoxChecked(bool)));
}


void ActionDialog::onSnapshotCheckBoxChecked(bool checked)
{
	if (!checked) return;

	CustomCheckBox *senderComBox = static_cast<CustomCheckBox *>(sender());
    for (int i(0); i < sys_info.max_cameras && i < MAX_CAMERA; i++)
    {
    	QCheckBox *checkBox = this->snapshotBox+i;
		if (!checkBox) continue;

		if (checkBox == senderComBox) continue;
		if (checkBox->isChecked() == true)
		{
			checkBox->setCheckState(Qt::Unchecked);
		}
    }
}

猜你喜欢

转载自blog.csdn.net/y7u8t6/article/details/83657935