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);
	}
}
相关推荐
Z1Jxxx21 小时前
01序列01序列
开发语言·c++·算法
坚定学代码1 天前
基于观察者模式的ISO C++信号槽实现
开发语言·c++·观察者模式·ai
ha20428941941 天前
Linux操作系统学习记录之---TcpSocket
linux·网络·c++·学习
AI视觉网奇1 天前
ue5 插件 WebSocket
c++·ue5
左直拳1 天前
将c++程序部署到docker
开发语言·c++·docker
恒者走天下1 天前
AI智能体通讯项目(底层AI通讯协议实现)
c++
英雄各有见1 天前
Chapter 5.1.1: 编写你的第一个GPU kernel——Cuda Basics
c++·gpu·cuda·hpc
梵尔纳多1 天前
OpenGL着色器语言(GLSL)
c++·opengl·着色器
net3m331 天前
单片机屏幕多级菜单系统之当前屏幕号+屏幕菜单当前深度 机制
c语言·c++·算法
mmz12071 天前
二分查找(c++)
开发语言·c++·算法