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);
	}
}
相关推荐
by209993 分钟前
C++ 多态:同一个基类接口,调用不同的函数
开发语言·c++·经验分享·多态
bug和崩溃我都要20 分钟前
QT 开发的专业截图录屏工具 - macOS版 / Windows版
windows·qt·mac·录屏·截屏
colinu32 分钟前
C++ 异步任务与线程生命周期:`std::async`、`future`、`thread`、`jthread` 与协作式退出
java·jvm·c++
wuminyu1 小时前
ForkJoinPool窃取线程在扫描其他WorkQueue时的随机采样算法与Phase线程挂起唤醒机制解析
java·linux·c语言·jvm·c++
longlongzihan1 小时前
链表找环:Floyd 判圈算法(LeetCode 141 & 142 )
c++·算法·leetcode·链表
liulilittle1 小时前
Linux 下 select 测试函数
linux·服务器·网络·数据库·c++·select·c
无忧.芙桃2 小时前
C++语言原理与实践(十二):list类的底层实现
c++·windows·list
沫璃染墨2 小时前
《Linux工程实践篇(二):线程池实战——从线程安全单例到完整源码实现》
linux·开发语言·c++·单例模式·设计模式·系统架构
有只小白叫岳飒3 小时前
c++智能指针 unique_ptr与函数调用
c++
Leo.yuan3 小时前
Kafka+Flink拼凑,还是FineDataLink 5.0一体化?实时数据处理的两种思路
c++·mfc