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);
	}
}
相关推荐
挖矿大亨35 分钟前
C++中深拷贝与浅拷贝的原理
开发语言·c++·算法
Bruce_kaizy42 分钟前
c++图论——生成树之Kruskal&Prim算法
c++·算法·图论
雾岛听蓝2 小时前
C++:模拟实现string类
开发语言·c++
XFF不秃头2 小时前
力扣刷题笔记-合并区间
c++·笔记·算法·leetcode
编程之路,妙趣横生2 小时前
STL(七) unordered_set 与 unordered_map 基本用法 + 模拟实现
c++
寂柒2 小时前
c++--
c++
wregjru3 小时前
【读书笔记】Effective C++ 条款3:尽可能使用const
开发语言·c++
追烽少年x3 小时前
Qt中线程同步类介绍(一)
qt
树欲静而风不止慢一点吧4 小时前
Qt5/6版本对应的Emscripten版本
开发语言·qt
历程里程碑4 小时前
滑动窗口秒解LeetCode字母异位词
java·c语言·开发语言·数据结构·c++·算法·leetcode