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);
	}
}
相关推荐
Code Warrior40 分钟前
【每日算法】专题五_位运算
开发语言·c++
OneQ6665 小时前
C++讲解---创建日期类
开发语言·c++·算法
Coding小公仔7 小时前
C++ bitset 模板类
开发语言·c++
菜鸟看点8 小时前
自定义Cereal XML输出容器节点
c++·qt
漫步企鹅8 小时前
【蓝牙】Linux Qt4查看已经配对的蓝牙信息
linux·qt·蓝牙·配对
new_zhou9 小时前
Windows qt打包编译好的程序
开发语言·windows·qt·打包程序
悲伤小伞9 小时前
linux_git的使用
linux·c语言·c++·git
ysa0510309 小时前
数论基础知识和模板
数据结构·c++·笔记·算法
小小小小王王王12 小时前
求猪肉价格最大值
数据结构·c++·算法
岁忧13 小时前
(LeetCode 面试经典 150 题 ) 58. 最后一个单词的长度 (字符串)
java·c++·算法·leetcode·面试·go