qt 信号槽默认参数 toggled 和 trigger的区别

 toggled和trigger区别
1. toggle 类似开关。 具有2个状态,打开/关闭。  使用这个信号,是在这2个状态之间切换。
2. trigger是一次性的。 点击后,无法改变状态。 要么是打开,要么是关闭。

参考:  http://blog.csdn.net/cgzhello1/article/details/7784665

  toggle在实物上有开关的意思,这跟我们物理实验用的开关是一回事,两头表示两个状态:合上和断开。于是更准确的译法应该是切换,在两个状态间进行转换。

在Qt中,checkable按纽或是图标的槽函数应该用toggled()事件来激活,也是这个道理。


在Qt中,checkable按纽或是图标的槽函数应该用toggled()事件来激活,也是这个道理。

     trigger更有触发的意思。这个单词还有另一个意思就是板机,枪械上用来发射子弹的那种。我们很容易想到板机是没有开/关两种状态的,不能说让它一直关上,一直发射子弹,至少在造词时并没有想到激光武器一说,我想如果针对激光武器,那么要fire的时候应该就不是扣trigger了,而是按toggle。在Qt中,一般的按纽(uncheckable)的激活方式即是triggered()。




在Qt中,checkable按纽或是图标的槽函数应该用toggled()事件来激活,也是这个道理。


在Qt中,checkable按纽或是图标的槽函数应该用toggled()事件来激活,也是这个道理。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Qt 中,可以通过使用 QRadioButton 控件来创建单选按钮。以下是一个示例代码,该代码创建了两个单选按钮并连接了它们的函数。 首先,在 UI 文件中添加两个 QRadioButton 控件,分别为 radioButton1 和 radioButton2。然后在函数中连接这两个控件的 toggled 信号。 ```cpp // 在头文件中声明两个 QRadioButton 指针变量 QRadioButton *radioButton1; QRadioButton *radioButton2; // 在构造函数中初始化控件,并连接函数 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // 创建两个单选按钮控件 radioButton1 = new QRadioButton("Button 1", this); radioButton1->setGeometry(QRect(10, 10, 100, 30)); radioButton2 = new QRadioButton("Button 2", this); radioButton2->setGeometry(QRect(10, 50, 100, 30)); // 连接两个控件的 toggled 信号函数 connect(radioButton1, SIGNAL(toggled(bool)), this, SLOT(onRadioButtonToggled())); connect(radioButton2, SIGNAL(toggled(bool)), this, SLOT(onRadioButtonToggled())); } // 定义函数 void MainWindow::onRadioButtonToggled() { if (radioButton1->isChecked()) { qDebug() << "Button 1 checked"; } else if (radioButton2->isChecked()) { qDebug() << "Button 2 checked"; } } ``` 在上面的代码中,我们创建了两个 QRadioButton 控件,并将它们的 toggled 信号连接到函数 onRadioButtonToggled()。在函数中,我们使用 isChecked() 函数来检查哪个单选按钮被选中,并输出相应的消息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值