Qt连接所有同类部件到同一个槽函数

cpp 复制代码
void MainWindow::AutoConnectSignals() 
{
	// 查找所有 QSpinBox
	const auto spinBoxes = findChildren<QSpinBox*>();
	for (auto *spinBox : spinBoxes)
	{
		connect(spinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ParameterWidget::SpinBoxValueChanged);
	}

	// 查找所有 QDoubleSpinBox
	const auto doubleSpinBoxes = findChildren<QDoubleSpinBox*>();
	for (auto *doubleSpinBox : doubleSpinBoxes) 
	{
		connect(doubleSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &ParameterWidget::SpinBoxValueChanged);
	}

	// 查找所有 QLineEdit
	const auto lineEdites = findChildren<QLineEdit*>();
	for (auto *lineEdit : lineEdites) 
	{
		connect(lineEdit, &QLineEdit::textChanged, this, &ParameterWidget::LineEditTextChanged);
	}
}
相关推荐
Neteen6 分钟前
【数据结构-思维导图】第二章:线性表
数据结构·c++·算法
灰色小旋风39 分钟前
力扣——第7题(C++)
c++·算法·leetcode
Ralph_Y1 小时前
C++网络:一
开发语言·网络·c++
2345VOR1 小时前
【QT的pyside6开发使用】
开发语言·qt
程序猿编码1 小时前
探秘 SSL/TLS 服务密码套件检测:原理、实现与核心设计(C/C++代码实现)
c语言·网络·c++·ssl·密码套件
Ronin3052 小时前
【Qt常用控件】控件概述和QWidget 核心属性
开发语言·qt·常用控件·qwidget核心属性
故事和你912 小时前
sdut-程序设计基础Ⅰ-实验二选择结构(1-8)
大数据·开发语言·数据结构·c++·算法·优化·编译原理
像素猎人2 小时前
数据结构之顺序表的插入+删除+查找+修改操作【主函数一步一输出,代码更加清晰直观】
数据结构·c++·算法
蜡笔小马2 小时前
32.Boost.Geometry 空间索引:R-Tree 接口详解
c++·boost·r-tree
想进个大厂3 小时前
代码随想录day63 64 65 66 图论08 09 10 11
c++·算法·图论