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);
	}
}
相关推荐
远离UE43 小时前
UE5 compute shader 原子加
开发语言·c++·ue5
C+-C资深大佬3 小时前
C++ 显式类型转换详解:static_cast、dynamic_cast、const_cast、reinterpret_cast
开发语言·c++
luj_17685 小时前
心形曲线轨迹控制三大关键技术
c语言·开发语言·c++·经验分享·算法
取地址符5 小时前
C++学习笔记(基于learn-cxx)(1)
c++·经验分享·笔记·学习
思麟呀6 小时前
C++17(三)if constexpr+折叠表达式
开发语言·c++
ysa0510306 小时前
【板子】ST表
c++·笔记·算法·板子
CHHH_HHH6 小时前
【C++11】深入解析C++可变参数模板
开发语言·c++·算法·stl·c++11
十五年专注C++开发7 小时前
fatal error C1189: #error: WinSock.h has already been included 的解决方案
c++·socket·boost
旖-旎10 小时前
《LeetCode 53 最大子数组和 || LeetCode 918 环形子数组的最大和》
c++·算法·leetcode·动态规划
qeen8710 小时前
〖C++〗STL简介:发展历史、六大组件与简单应用
c++·学习·stl·模板